@@ -41,7 +41,9 @@ Install-Package RazorLight -Version 3.0.0
4141The simplest scenario is to create a template from string. Each template must have a ` templateKey ` that is associated with it, so you can render the same template next time without recompilation.
4242
4343<!-- snippet: simple -->
44+
4445<a id =' snippet-simple ' ></a >
46+
4547``` cs
4648var engine = new RazorLightEngineBuilder ()
4749 // required to have a default RazorLightProject type,
@@ -56,13 +58,17 @@ ViewModel model = new ViewModel {Name = "John Doe"};
5658
5759string result = await engine .CompileRenderStringAsync (" templateKey" , template , model );
5860```
61+
5962<sup ><a href =' /tests/RazorLight.Tests/Snippets/Snippets.cs#L18-L32 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-simple ' title =' Start of snippet ' >anchor</a ></sup >
63+
6064<!-- endSnippet -->
6165
6266To render a compiled template:
6367
6468<!-- snippet: RenderCompiledTemplate -->
69+
6570<a id =' snippet-rendercompiledtemplate ' ></a >
71+
6672``` cs
6773var cacheResult = engine .Handler .Cache .RetrieveTemplate (" templateKey" );
6874if (cacheResult .Success )
@@ -71,7 +77,9 @@ if(cacheResult.Success)
7177 string result = await engine .RenderTemplateAsync (templatePage , model );
7278}
7379```
80+
7481<sup ><a href =' /tests/RazorLight.Tests/Snippets/Snippets.cs#L39-L46 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-rendercompiledtemplate ' title =' Start of snippet ' >anchor</a ></sup >
82+
7583<!-- endSnippet -->
7684
7785# Template sources
@@ -83,7 +91,9 @@ RazorLight can resolve templates from any source, but there are a built-in provi
8391When resolving a template from filesystem, templateKey - is a relative path to the root folder, that you pass to RazorLightEngineBuilder.
8492
8593<!-- snippet: FileSource -->
94+
8695<a id =' snippet-filesource ' ></a >
96+
8797``` cs
8898var engine = new RazorLightEngineBuilder ()
8999 .UseFileSystemProject (" C:/RootFolder/With/YourTemplates" )
@@ -93,7 +103,9 @@ var engine = new RazorLightEngineBuilder()
93103var model = new {Name = " John Doe" };
94104string result = await engine .CompileRenderAsync (" Subfolder/View.cshtml" , model );
95105```
106+
96107<sup ><a href =' /tests/RazorLight.Tests/Snippets/Snippets.cs#L51-L60 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-filesource ' title =' Start of snippet ' >anchor</a ></sup >
108+
97109<!-- endSnippet -->
98110
99111## EmbeddedResource source
@@ -115,7 +127,9 @@ Project.Core/
115127```
116128
117129<!-- snippet: EmbeddedResourceSource -->
130+
118131<a id =' snippet-embeddedresourcesource ' ></a >
132+
119133``` cs
120134var engine = new RazorLightEngineBuilder ()
121135 .UseEmbeddedResourcesProject (typeof (SomeService ).Assembly )
@@ -125,13 +139,17 @@ var engine = new RazorLightEngineBuilder()
125139var model = new Model ();
126140string html = await engine .CompileRenderAsync (" EmailTemplates.Body" , model );
127141```
142+
128143<sup ><a href =' /tests/RazorLight.Tests/Snippets/Snippets.cs#L65-L74 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-embeddedresourcesource ' title =' Start of snippet ' >anchor</a ></sup >
144+
129145<!-- endSnippet -->
130146
131147Setting the root namespace allows you to leave that piece off when providing the template name as the key:
132148
133149<!-- snippet: EmbeddedResourceSourceWithRootNamespace -->
150+
134151<a id =' snippet-embeddedresourcesourcewithrootnamespace ' ></a >
152+
135153``` cs
136154var engine = new RazorLightEngineBuilder ()
137155 .UseEmbeddedResourcesProject (typeof (SomeService ).Assembly , " Project.Core.EmailTemplates" )
@@ -141,7 +159,9 @@ var engine = new RazorLightEngineBuilder()
141159var model = new Model ();
142160string html = await engine .CompileRenderAsync (" Body" , model );
143161```
162+
144163<sup ><a href =' /tests/RazorLight.Tests/Snippets/Snippets.cs#L79-L88 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-embeddedresourcesourcewithrootnamespace ' title =' Start of snippet ' >anchor</a ></sup >
164+
145165<!-- endSnippet -->
146166
147167## Custom source
0 commit comments