11using CMS . ContactManagement ;
22using CMS . DataEngine ;
3+ using CMS . Websites . Routing ;
34
45using Kentico . Content . Web . Mvc ;
56using Kentico . PageBuilder . Web . Mvc ;
@@ -26,19 +27,22 @@ internal class CodeSnippetTagHelperComponent : TagHelperComponent
2627 private readonly IFileVersionProvider fileVersionProvider ;
2728 private readonly IHttpContextAccessor httpContextAccessor ;
2829 private readonly IWebPageDataContextRetriever webPageDataContextRetriever ;
30+ private readonly IWebsiteChannelContext websiteChannelContext ;
2931
3032 public CodeSnippetTagHelperComponent (
3133 IChannelCodeSnippetsService codeSnippetsContext ,
3234 IUrlHelperFactory urlHelperFactory ,
3335 IFileVersionProvider fileVersionProvider ,
3436 IHttpContextAccessor httpContextAccessor ,
35- IWebPageDataContextRetriever webPageDataContextRetriever )
37+ IWebPageDataContextRetriever webPageDataContextRetriever ,
38+ IWebsiteChannelContext websiteChannelContext )
3639 {
3740 this . codeSnippetsContext = codeSnippetsContext ;
3841 this . urlHelperFactory = urlHelperFactory ;
3942 this . httpContextAccessor = httpContextAccessor ;
4043 this . fileVersionProvider = fileVersionProvider ;
4144 this . webPageDataContextRetriever = webPageDataContextRetriever ;
45+ this . websiteChannelContext = websiteChannelContext ;
4246 }
4347
4448 /// <summary>
@@ -52,16 +56,20 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
5256 {
5357 var contact = ContactManagementContext . CurrentContact ;
5458
55- if ( ! webPageDataContextRetriever . TryRetrieve ( out var webPageDataContext ) )
59+ if ( websiteChannelContext . WebsiteChannelID <= 0 )
5660 {
5761 return ;
5862 }
5963
60- var contentTypeName = webPageDataContext . WebPage . ContentTypeName ;
61- var dataClass = DataClassInfoProvider . GetDataClassInfo ( contentTypeName ) ;
62-
6364 // Get the current page's content type ID
64- int ? contentTypeId = dataClass ? . ClassID ;
65+ int ? contentTypeId = null ;
66+ if ( webPageDataContextRetriever . TryRetrieve ( out var webPageDataContext ) )
67+ {
68+ var contentTypeName = webPageDataContext . WebPage . ContentTypeName ;
69+ var dataClass = DataClassInfoProvider . GetDataClassInfo ( contentTypeName ) ;
70+
71+ contentTypeId = dataClass ? . ClassID ;
72+ }
6573
6674 var codeSnippets = await codeSnippetsContext . GetConsentedCodeSnippets ( contact , contentTypeId ) ;
6775
0 commit comments