W D Scripts

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):

  • ExecutionState contains the current IExecutionState object.
  • Context (and the ctx shorthand) contain the current execution context.
  • Document (and the doc shorthand) 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>, or IAsyncEnumerable<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> or IModule, the module(s) will be executed and the results will be output to the pipeline.
  • If the return value is an IContentProvider, IContentProviderFactory, or Stream the 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.