Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Episerver Script Block
Denina script can be executed inside of an EPiServer installation by means of the Text Include Block. This block is available via Nuget (it bundles DeninaSharp as a dependency):
PM> Install-Package EPiServerDeninaBlock
The block provides the following functionality:
- Two new commands for acquiring text: EPiServer.ReadLocalMedia and EPiServer.ReadParentMedia for reading the contents of files attached to the block, or to the page on which the block is embedded, respectively.
- A property for CSS which is injected and scoped to the block container (browser support is thin; see HTML Style Scoped Attribute)
- A property for extended template code (or any other use, really), the contents of which are provided to the script via a
- The ability to cache the results for a period of X minutes. This cache is invalidated whenever any of the properties of the block change.
- The ability to control error handling. Exceptions can thrown, suppressed, written to HTML comments, replaced with provided text, etc.
Below is a screencap of the block editing interface, populated with a sample script. All fields are explained under the screencap.
The Denina script itself. The output of the final command will be output to the page.
An optional editing area for template content -- or, really, any content. The contents of this textbox are simply injected into the pipeline as a variable called
$__template (that's with two underscores). It's often easier to put template-ish code here than inline as an argument parameter (as depicted in the screencap above).
CSS to be injected into a
STYLE element in the
HEAD of the page via Episerver's
ClientResources framework. (TODO: this should be renamed "Supporting CSS." It was previously injected via a
scoped CSS element, but that has been removed from the spec and is no longer supported.)
The content to display if
Display Error Content is selected from the "Error Behavior" dropdown. (TODO: this should be moved below "Error Behavior" in the interface.)
What to do if the script throws an exception. The options are:
- Display Error Content: Displays the content from the "Error Content" editor.
- Hide Block: Suppresses the exception and displays nothing.
- Throw Exception: Throws the exception raw. Recommended only for testing or development.
Output Debug Info: Outputs all
ExecutionLogentries as HTML (see Debug Data).
Output Hidden Error Message: Suppresses, hides the block, and outputs the
e.Messagestring as an HTML comment.
Number of minutes to cache the output of the block. The key is a hash of:
- The block ID
- The cache timeout
- The script commands
- The template value
If any of those values change, this will change the cache key and effectively invalidate the cache.
The image below links to a two-minute, narrated video of how to use the Episerver block to embed an RSS feed. (Yes, it's a link not an embedded player. GitHub does not allow embedded players.)