Skip to content

Commit daa6ecc

Browse files
authored
Merge pull request #1252 from colinin/fix-dynamic-template
fix(text-template): Fix the rendering error of the text content
2 parents 08ee2a9 + 62f159d commit daa6ecc

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/TextTemplateContentContributor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.Extensions.Caching.Distributed;
22
using Microsoft.Extensions.DependencyInjection;
33
using Microsoft.Extensions.Options;
4+
using System;
45
using System.Threading.Tasks;
56
using Volo.Abp.Caching;
67
using Volo.Abp.DependencyInjection;
@@ -42,6 +43,12 @@ protected async virtual Task<TextTemplateContentCacheItem> CreateTemplateContent
4243
var repository = context.ServiceProvider.GetRequiredService<ITextTemplateRepository>();
4344
var template = await repository.FindByNameAsync(context.TemplateDefinition.Name, culture);
4445

46+
// 2025/06/23 fixed 非内联本地化模板内容为空时,回退到默认文化
47+
if (template == null && !culture.IsNullOrWhiteSpace())
48+
{
49+
template = await repository.FindByNameAsync(context.TemplateDefinition.Name, context.TemplateDefinition.DefaultCultureName);
50+
}
51+
4552
return new TextTemplateContentCacheItem(
4653
template?.Name,
4754
template?.Content,

aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/TextTemplateContentProvider.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ public async override Task<string> GetContentOrNullAsync(
3030
bool tryDefaults = true,
3131
bool useCurrentCultureIfCultureNameIsNull = true)
3232
{
33-
var template = await TemplateDefinitionStore.GetAsync(templateName);
33+
var template = await TemplateDefinitionStore.GetOrNullAsync(templateName);
34+
if (template != null)
35+
{
36+
return await GetContentOrNullAsync(template, cultureName);
37+
}
3438

35-
return await GetContentOrNullAsync(template, cultureName);
39+
return await base.GetContentOrNullAsync(templateName, cultureName, tryDefaults, useCurrentCultureIfCultureNameIsNull);
3640
}
3741
}

aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/TextTemplateDefinitionInitializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public async virtual Task InitializeDynamicTemplates(CancellationToken cancellat
3636
using var scope = RootServiceProvider.CreateScope();
3737
var applicationLifetime = scope.ServiceProvider.GetService<IHostApplicationLifetime>();
3838
var token = applicationLifetime?.ApplicationStopping ?? cancellationToken;
39-
using (CancellationTokenProvider.Use(cancellationToken))
39+
using (CancellationTokenProvider.Use(token))
4040
{
4141
if (CancellationTokenProvider.Token.IsCancellationRequested)
4242
{

0 commit comments

Comments
 (0)