diff --git a/docs/en/Text-Templating-Razor.md b/docs/en/Text-Templating-Razor.md index 5bb00b4e82..700d262b9b 100644 --- a/docs/en/Text-Templating-Razor.md +++ b/docs/en/Text-Templating-Razor.md @@ -1,5 +1,9 @@ # Razor Integration + +The Razor template is a standard C# class, so you can freely use the functions of C#, such as `dependency injection`, using `LINQ`, custom methods, and even using `Repository`. + + ## Installation It is suggested to use the [ABP CLI](CLI.md) to install this package. @@ -41,13 +45,34 @@ You need to add the `MetadataReference` of the type used in the template to `CSh ````csharp public override void ConfigureServices(ServiceConfigurationContext context) { - Configure(options => + Configure(options => { options.References.Add(MetadataReference.CreateFromFile(typeof(YourModule).Assembly.Location)); }); } ```` +## Add MetadataReference for a template. + +You can add some `MetadataReference` to the template + +````csharp +public override void ConfigureServices(ServiceConfigurationContext context) +{ + services.Configure(options => + { + //Hello is template name. + options.TemplateReferences.Add("Hello", new List() + { + Assembly.Load("Microsoft.Extensions.Logging.Abstractions"), + Assembly.Load("Microsoft.Extensions.Logging") + } + .Select(x => MetadataReference.CreateFromFile(x.Location)) + .ToList()); + }); +} +```` + ## Defining Templates Before rendering a template, you should define it. Create a class inheriting from the `TemplateDefinitionProvider` base class: @@ -73,6 +98,11 @@ public class DemoTemplateDefinitionProvider : TemplateDefinitionProvider * `/Demos/Hello/Hello.cshtml` is the path of the template file. * `isInlineLocalized` is used to declare if you are using a single template for all languages (`true`) or different templates for each language (`false`). See the Localization section below for more. +### The Template Base + +Every `cshtml` template page needs to inherit `RazorTemplatePageBase` or `RazorTemplatePageBase`. +There are some useful properties in the base class that can be used in templates. eg: `Localizer`, `ServiceProvider`. + ### The Template Content `WithVirtualFilePath` indicates that we are using the [Virtual File System](Virtual-File-System.md) to store the template content. Create a `Hello.cshtml` file inside your project and mark it as "**embedded resource**" on the properties window: