diff --git a/TextTemplateDemo/DemoTemplateDefinitionProvider.cs b/TextTemplateDemo/DemoTemplateDefinitionProvider.cs
index dcb57f9df3..db635a3901 100644
--- a/TextTemplateDemo/DemoTemplateDefinitionProvider.cs
+++ b/TextTemplateDemo/DemoTemplateDefinitionProvider.cs
@@ -19,8 +19,7 @@ public override void Define(ITemplateDefinitionContext context)
new TemplateDefinition(
name: "PasswordReset",
localizationResource: typeof(DemoResource)
- )
- .WithVirtualFilePath(
+ ).WithVirtualFilePath(
"/Demos/PasswordReset/PasswordReset.tpl", //template content path
isInlineLocalized: true
)
@@ -29,13 +28,31 @@ public override void Define(ITemplateDefinitionContext context)
context.Add(
new TemplateDefinition(
name: "WelcomeEmail",
- defaultCultureName: "en"
- )
- .WithVirtualFilePath(
+ defaultCultureName: "en",
+ layout: "EmailLayout" //Set the LAYOUT
+ ).WithVirtualFilePath(
"/Demos/WelcomeEmail/Templates", //template content folder
isInlineLocalized: false
)
);
+
+ context.Add(
+ new TemplateDefinition(
+ "EmailLayout",
+ isLayout: true
+ ).WithVirtualFilePath(
+ "/Demos/EmailLayout/EmailLayout.tpl", //template content path
+ isInlineLocalized: true
+ )
+ );
+
+ context.Add(
+ new TemplateDefinition("GlobalContextUsage")
+ .WithVirtualFilePath(
+ "/Demos/GlobalContext/GlobalContextUsage.tpl",
+ isInlineLocalized: true
+ )
+ );
}
}
}
diff --git a/TextTemplateDemo/Demos/EmailLayout/EmailLayout.tpl b/TextTemplateDemo/Demos/EmailLayout/EmailLayout.tpl
new file mode 100644
index 0000000000..57453a027f
--- /dev/null
+++ b/TextTemplateDemo/Demos/EmailLayout/EmailLayout.tpl
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+ {{content}}
+
+
\ No newline at end of file
diff --git a/TextTemplateDemo/Demos/GlobalContext/GlobalContextUsage.tpl b/TextTemplateDemo/Demos/GlobalContext/GlobalContextUsage.tpl
new file mode 100644
index 0000000000..be65f645e6
--- /dev/null
+++ b/TextTemplateDemo/Demos/GlobalContext/GlobalContextUsage.tpl
@@ -0,0 +1 @@
+A global object value: {{myGlobalObject}}
\ No newline at end of file
diff --git a/TextTemplateDemo/Demos/GlobalContext/GlobalContextUsageDemo.cs b/TextTemplateDemo/Demos/GlobalContext/GlobalContextUsageDemo.cs
new file mode 100644
index 0000000000..8627c3ae0e
--- /dev/null
+++ b/TextTemplateDemo/Demos/GlobalContext/GlobalContextUsageDemo.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Volo.Abp.DependencyInjection;
+using Volo.Abp.TextTemplating;
+
+namespace TextTemplateDemo.Demos.GlobalContext
+{
+ public class GlobalContextUsageDemo : ITransientDependency
+ {
+ private readonly ITemplateRenderer _templateRenderer;
+
+ public GlobalContextUsageDemo(ITemplateRenderer templateRenderer)
+ {
+ _templateRenderer = templateRenderer;
+ }
+
+ public async Task RunAsync()
+ {
+ var result = await _templateRenderer.RenderAsync(
+ "GlobalContextUsage",
+ globalContext: new Dictionary
+ {
+ {"myGlobalObject", "TEST VALUE"}
+ }
+ );
+
+ Console.WriteLine(result);
+ }
+ }
+}
diff --git a/TextTemplateDemo/Demos/TemplateContent/TemplateContentDemo.cs b/TextTemplateDemo/Demos/TemplateContent/TemplateContentDemo.cs
new file mode 100644
index 0000000000..97afe3cbe8
--- /dev/null
+++ b/TextTemplateDemo/Demos/TemplateContent/TemplateContentDemo.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Threading.Tasks;
+using Volo.Abp.DependencyInjection;
+using Volo.Abp.TextTemplating;
+
+namespace TextTemplateDemo.Demos.TemplateContent
+{
+ public class TemplateContentDemo : ITransientDependency
+ {
+ private readonly ITemplateContentProvider _templateContentProvider;
+
+ public TemplateContentDemo(ITemplateContentProvider templateContentProvider)
+ {
+ _templateContentProvider = templateContentProvider;
+ }
+
+ public async Task RunAsync()
+ {
+ var result = await _templateContentProvider
+ .GetContentOrNullAsync("Hello");
+
+ Console.WriteLine(result);
+ }
+ }
+}
diff --git a/TextTemplateDemo/Other/MyTemplateContentProvider.cs b/TextTemplateDemo/Other/MyTemplateContentProvider.cs
new file mode 100644
index 0000000000..aae5877e04
--- /dev/null
+++ b/TextTemplateDemo/Other/MyTemplateContentProvider.cs
@@ -0,0 +1,17 @@
+using System.Threading.Tasks;
+using Volo.Abp.DependencyInjection;
+using Volo.Abp.TextTemplating;
+
+namespace TextTemplateDemo.Other
+{
+ public class MyTemplateContentProvider : ITemplateContentContributor, ITransientDependency
+ {
+ public async Task GetOrNullAsync(TemplateContentContributorContext context)
+ {
+ var templateName = context.TemplateDefinition.Name;
+
+ //TODO: Try to find content from another source
+ return null;
+ }
+ }
+}
diff --git a/TextTemplateDemo/Program.cs b/TextTemplateDemo/Program.cs
index b3c12335c2..2c6182765f 100644
--- a/TextTemplateDemo/Program.cs
+++ b/TextTemplateDemo/Program.cs
@@ -1,8 +1,10 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
+using TextTemplateDemo.Demos.GlobalContext;
using TextTemplateDemo.Demos.Hello;
using TextTemplateDemo.Demos.PasswordReset;
+using TextTemplateDemo.Demos.TemplateContent;
using TextTemplateDemo.Demos.WelcomeEmail;
using Volo.Abp;
@@ -22,6 +24,8 @@ static async Task Main(string[] args)
var helloDemo = application.ServiceProvider.GetRequiredService();
var passwordResetDemo = application.ServiceProvider.GetRequiredService();
var welcomeEmailDemo = application.ServiceProvider.GetRequiredService();
+ var globalContextDemo = application.ServiceProvider.GetRequiredService();
+ var templateContentDemo = application.ServiceProvider.GetRequiredService();
await helloDemo.RunAsync();
await helloDemo.RunWithAnonymousModelAsync();
@@ -31,6 +35,10 @@ static async Task Main(string[] args)
await welcomeEmailDemo.RunAsync("en");
await welcomeEmailDemo.RunAsync("tr");
+ await globalContextDemo.RunAsync();
+
+ await templateContentDemo.RunAsync();
+
Console.WriteLine();
Console.WriteLine("Press enter to exit...");
Console.ReadLine();
diff --git a/TextTemplateDemo/TextTemplateDemo.csproj b/TextTemplateDemo/TextTemplateDemo.csproj
index cca7989d0a..7f5b7e3f75 100644
--- a/TextTemplateDemo/TextTemplateDemo.csproj
+++ b/TextTemplateDemo/TextTemplateDemo.csproj
@@ -1,4 +1,4 @@
-
+
Exe
@@ -8,8 +8,11 @@
-
+
+
+
+