Get SharpScript variables

SharpScript is an awesome product and I am on my way to translate a Yeoman project to be done in .Net with SharpScript and ServiceStack.

When we RenderScript a template, is it possible to get its created variables?
I would like to access both: final resulting text and final resulting variables.

I know we can use ScriptScopeContext in a method, but this can only be used with methods to be pass to Args (right?).

Thank you.

An example would help as I’m not really sure how you’re using #Script (e.g. in a #Script Page) or what APIs you’re using.

But if you use toGlobal to assign a variable (e.g. instead of to which only assigns it to the local scope) it sets the variable in the pageResult.Args Dictionary which you can access after the script is rendered, e.g:

var context = new ScriptContext().Init();
var dynamicPage = context.OneTimePage(
  "Time is now {{now |> dateFormat('HH:mm:ss') |> toGlobal => date}} {{date}}"); 
var pageResult = new PageResult(dynamicPage);

var output = pageResult.RenderScript();
var renderedDate = pageResult.Args["date"]; 
1 Like

I was not using a Page. It works perfectly, thanks!!