Browse Source

Merge pull request #1252 from colinin/fix-dynamic-template

fix(text-template): Fix the rendering error of the text content
pull/1267/head
yx lin 9 months ago
committed by GitHub
parent
commit
daa6ecc14b
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/TextTemplateContentContributor.cs
  2. 8
      aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/TextTemplateContentProvider.cs
  3. 2
      aspnet-core/modules/text-templating/LINGYUN.Abp.TextTemplating.Domain/LINGYUN/Abp/TextTemplating/TextTemplateDefinitionInitializer.cs

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

@ -1,6 +1,7 @@
using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Caching; using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
@ -42,6 +43,12 @@ public class TextTemplateContentContributor : ITemplateContentContributor, ITran
var repository = context.ServiceProvider.GetRequiredService<ITextTemplateRepository>(); var repository = context.ServiceProvider.GetRequiredService<ITextTemplateRepository>();
var template = await repository.FindByNameAsync(context.TemplateDefinition.Name, culture); var template = await repository.FindByNameAsync(context.TemplateDefinition.Name, culture);
// 2025/06/23 fixed 非内联本地化模板内容为空时,回退到默认文化
if (template == null && !culture.IsNullOrWhiteSpace())
{
template = await repository.FindByNameAsync(context.TemplateDefinition.Name, context.TemplateDefinition.DefaultCultureName);
}
return new TextTemplateContentCacheItem( return new TextTemplateContentCacheItem(
template?.Name, template?.Name,
template?.Content, template?.Content,

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

@ -30,8 +30,12 @@ public class TextTemplateContentProvider : TemplateContentProvider, ITransientDe
bool tryDefaults = true, bool tryDefaults = true,
bool useCurrentCultureIfCultureNameIsNull = true) bool useCurrentCultureIfCultureNameIsNull = true)
{ {
var template = await TemplateDefinitionStore.GetAsync(templateName); var template = await TemplateDefinitionStore.GetOrNullAsync(templateName);
if (template != null)
{
return await GetContentOrNullAsync(template, cultureName);
}
return await GetContentOrNullAsync(template, cultureName); return await base.GetContentOrNullAsync(templateName, cultureName, tryDefaults, useCurrentCultureIfCultureNameIsNull);
} }
} }

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

@ -36,7 +36,7 @@ public class TextTemplateDefinitionInitializer : ITransientDependency
using var scope = RootServiceProvider.CreateScope(); using var scope = RootServiceProvider.CreateScope();
var applicationLifetime = scope.ServiceProvider.GetService<IHostApplicationLifetime>(); var applicationLifetime = scope.ServiceProvider.GetService<IHostApplicationLifetime>();
var token = applicationLifetime?.ApplicationStopping ?? cancellationToken; var token = applicationLifetime?.ApplicationStopping ?? cancellationToken;
using (CancellationTokenProvider.Use(cancellationToken)) using (CancellationTokenProvider.Use(token))
{ {
if (CancellationTokenProvider.Token.IsCancellationRequested) if (CancellationTokenProvider.Token.IsCancellationRequested)
{ {

Loading…
Cancel
Save