Files with a .csx or .cs extension are processed as a script. Similar to computed values, full scripts also provide access to a number of predefined global properties (see the ScriptBase class in Statiq.Core for all script properties):
ExecutionStatecontains the currentIExecutionStateobject.Context(and thectxshorthand) contain the current execution context.Document(and thedocshorthand) contain the current document.PipelineName: Gets the name of the currently executing pipeline.Pipeline: Gets the currently executing pipeline.Phase: Gets the currently executing phase of the current pipeline.Parent: Gets the parent execution context if currently in a nested module.Module: Gets the current executing module.Inputs: The collection of input documents to the current module.
Front Matter
Scripts support a special syntax for front matter. In addition to the standard --- front matter delimiter, a script can also delimit front matter using a comment block starting on the first line:
/*
Title: My Page
*/
return "This is my page!";
Return Values
The script will behave differently depending on the value(s) it returns:
- If the return value is
null, a document representing the current file will be output to the pipeline. - If the return value is a
IDocument,IEnumerable<IDocument>, orIAsyncEnumerable<IDocument>the returned document(s) will be output to the pipeline. - If the return value is
IEnumerable<KeyValuePair<string, object>>, the document will be cloned with the returned items as metadata and output to the pipeline. - If the return value is a
IEnumerable<IModule>orIModule, the module(s) will be executed and the results will be output to the pipeline. - If the return value is an
IContentProvider,IContentProviderFactory, orStreamthe document will be output to the pipeline with new content. - If the return value is anything else, the content of the document will changed to the string value and output to the pipeline.