RenderRazor Class
Parses, compiles, and renders Razor templates.
Namespace
Statiq.Razor
Interfaces
Base Types
graph BT Type-->Base0["Module"] click Base0 "/api/Statiq.Common/Module" Base0-->Base1["object"] Type-.->Interface0["IModule"] click Interface0 "/api/Statiq.Common/IModule" Type["RenderRazor"] class Type type-node

Syntax

public class RenderRazor : Module, IModule

Remarks

Razor is the template language used by ASP.NET MVC. This module can parse and compile Razor templates and then render them to HTML. While a bit outdated, this guide is a good quick reference for the Razor language syntax. This module uses the Razor engine from ASP.NET Core.

Whenever possible, the same conventions as the Razor engine in ASP.NET MVC were used. It's important to keep in mind however, that this is not ASP.NET MVC. Many features you may be used to will not work (like most of the HtmlHelper extensions) and others just don't make sense (like the concept of actions and controllers). Also, while property names and classes in the two engines have similar names(such as HtmlHelper) they are not the same, and code intended to extend the capabilities of Razor in ASP.NET MVC probably won't work. That said, a lot of functionality does function the same as it does in ASP.NET MVC.

This module requires Razor services to be registered before use with Statiq.Razor.IServiceCollectionExtensions.AddRazor(IServiceCollection,Statiq.Common.IReadOnlyFileSystem). This is done automatically when using Statiq.App and the Bootstrapper.

Constructors

Name Summary
RenderRazor(Type) Parses Razor templates in each input document and outputs documents with rendered HTML content. If basePageType is specified, it will be used as the base type for Razor pages. The new base type must derive from StatiqRazorPage<TModel>.

Methods

Name Return Value Summary
AfterExecution(IExecutionContext, ExecutionOutputs) void
Called after each module execution.
Inherited from Module
AfterExecutionAsync(IExecutionContext, ExecutionOutputs) Task
Called after each module execution.
Inherited from Module
BeforeExecution(IExecutionContext) void
Called before each module execution.
Inherited from Module
BeforeExecutionAsync(IExecutionContext) Task
Called before each module execution.
Inherited from Module
ExecuteAsync(IExecutionContext) Task<IEnumerable<IDocument>>
This should not be called directly, instead call IExecutionContext.Execute() if you need to execute a module from within another module.
Inherited from Module
ExecuteContextAsync(IExecutionContext) Task<IEnumerable<IDocument>>
Executes the module once for all input documents.
ExecuteInputAsync(IDocument, IExecutionContext) Task<IEnumerable<IDocument>>
Executes the module.
Inherited from Module
Finally(IExecutionContext) void
Called after each module execution, even if an exception is thrown during execution.
Inherited from Module
FinallyAsync(IExecutionContext) Task
Called after each module execution, even if an exception is thrown during execution.
Inherited from Module
IgnorePrefix(string) RenderRazor
Specifies a file prefix to ignore. If a document has a metadata value for SourceFileName and that metadata value starts with the specified prefix, that document will not be processed or output by the module. By default, the Razor module ignores all documents prefixed with an underscore (_). Specifying null will result in no documents being ignored.
WithLayout(Config<NormalizedPath>) RenderRazor
Specifies a layout file to use for all Razor pages processed by this module. This lets you specify a different layout file for each document.
WithLayout(Config<string>) RenderRazor
Specifies a layout file to use for all Razor pages processed by this module. This lets you specify a different layout file for each document.
WithModel(Config<object>) RenderRazor
Specifies a model to use for each page based on the current input document and context.
WithViewData(string, Config<object>) RenderRazor
Specifies ViewData to use for each page based on the current input document and context.
WithViewStart(Config<NormalizedPath>) RenderRazor
Specifies an alternate ViewStart file to use for all Razor pages processed by this module. This lets you specify a different ViewStart file for each document. For example, you could return a ViewStart based on document location or document metadata. Returning null from the function reverts back to the default ViewStart search behavior for that document.
WithViewStart(Config<string>) RenderRazor
Specifies an alternate ViewStart file to use for all Razor pages processed by this module. This lets you specify a different ViewStart file for each document. For example, you could return a ViewStart based on document location or document metadata. Returning null from the function reverts back to the default ViewStart search behavior for that document.

Extension Methods