Created
April 11, 2024 13:12
-
-
Save sreekrishnan1993/82c182e137aa4c40b700c68687c65312 to your computer and use it in GitHub Desktop.
Scriban Embedded function to get List of Categories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
using MyProject.Models; | |
using Scriban.Runtime; | |
using Sitecore.Data; | |
using Sitecore.Data.Items; | |
using Sitecore.XA.Foundation.Scriban.Pipelines.GenerateScribanContext; | |
namespace MyProject.Pipelines.GenerateScribanContext | |
{ | |
public class AddCategoryFunction : IGenerateScribanContextProcessor | |
{ | |
private delegate List<CategoryModel> GetCategoriesDelegate(Item currentPageItem); | |
public void Process(GenerateScribanContextPipelineArgs args) | |
{ | |
args.GlobalScriptObject.Import("sc_article_getcategories", new GetCategoriesDelegate(GetCategories)); | |
} | |
public List<CategoryModel> GetCategories(Item currentPageItem) | |
{ | |
List<CategoryModel> articleCategories = new List<CategoryModel>(); | |
// Perform your code logic here | |
return articleCategories; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/"> | |
<sitecore role:require="Standalone or ContentManagement or ContentDelivery"> | |
<pipelines> | |
<generateScribanContext> | |
<processor type="MyProject.Pipelines.GenerateScribanContext.AddCategoryFunction, MyProject" resolve="true" /> | |
</generateScribanContext> | |
</pipelines> | |
</sitecore> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment