From 3c6f1ebf8c163b4750d86bca4baeda67895a0bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 14 May 2020 01:09:10 +0300 Subject: [PATCH] Update Text-Templating.md --- docs/en/Text-Templating.md | 44 ++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/docs/en/Text-Templating.md b/docs/en/Text-Templating.md index 84d1fff3d1..c722d2650e 100644 --- a/docs/en/Text-Templating.md +++ b/docs/en/Text-Templating.md @@ -10,6 +10,8 @@ It is very similar to an ASP.NET Core Razor View (or Page): RAZOR VIEW (or PAGE) + MODEL => HTML CONTENT +You can use the rendered output for any purpose, like sending emails or preparing some reports. + ### Example Here, a simple template: @@ -346,35 +348,31 @@ context.Add( ## Global Context +ABP passes the `model` that can be used to access to the model inside the template. You can pass more global variables if you need. +An example template content: +```` +A global object value: {{myGlobalObject}} +```` -## Rendering - -When one template is registered, it is easy to render and get the result with `ITemplateRenderer` service. - -`ITemplateRenderer` service has one method that named `RenderAsync` and to render your content and it is requires some parameters. - -- `templateName` (_string_) -- `model` (_object_) -- `cultureName` (_string_) -- `globalContext` (_dictionary_) - -`templateName` is exactly same with Template Definition Name. - -`model` is a dynamic object. This is using to put dynamic data into template. For more information, please look at [Scriban Documentation](https://github.com/lunet-io/scriban). - -`cultureName` is your destination rendering culture. When it is not exist, it will use the default culture. - -> If `cultureName` has a language tag it will try to find exact culture with tag, if it is not exist it will use the language family. - -> Example: If you try to render content with _"es-MX"_ it will search your template with _"es-MX"_ culture, when it fails to find, it will try to render _"es"_ culture content. If still can't find it will render the default culture content that you defined. - -`globalContext` = TODO - +This template assumes that that is a `myGlobalObject` object in the template rendering context. You can provide it like shown below: +````csharp +var result = await _templateRenderer.RenderAsync( + "GlobalContextUsage", + globalContext: new Dictionary + { + {"myGlobalObject", "TEST VALUE"} + } +); +```` +The rendering result will be: +```` +A global object value: TEST VALUE +````