如何从Razor将Sitecore的模板引擎改为Sharpy(How to change Sitecore's Templating Engine to Sharpy from Razor)

编程入门 行业动态 更新时间:2024-10-26 02:28:44
如何从Razor将Sitecore的模板引擎改为Sharpy(How to change Sitecore's Templating Engine to Sharpy from Razor)

长话短说客户端在前端为我们提供了Smarty模板。 Smarty (Sharpy)的.Net端口能够转换所有这些模板,就像我们使用RAZOR模板一样。 我无法弄清楚如何切换模板引擎来渲染Sharpy文件而不是RAZOR文件,这样就不需要将视图转换为RAZOR并避免现在正在发生的大量代码重写。

我尝试过的:

我在Sitecore MVC配置中添加了“sharpy”作为有效扩展名。 我在项目中添加了Sharpy.dll和System.ComponentModel.Composition.dll作为参考 - 根据Sharpy文档要求。 我在global.asax的application_start函数中添加了视图引擎(ViewEngines.Engines.Add(new SharpyViewEngine())); 我在初始化管道中添加了视图引擎 - 以确保它可用

错误:

没有为扩展名'.sharpy'注册的Build Provider。 您可以在machine.config或web.config中的部分中注册一个。 确保具有BuildProviderAppliesToAttribute属性,该属性包含值“Web”或“全部”。

我无法找到确切的原因。 谷歌搜索没有多大帮助,因为几乎所有用户都喜欢使用RAZOR。 还需要知道这里适用的构建提供程序。

更新:我可以找到关于它是如何完成的帖子/博客。 即使它是其他一些模板引擎也没关系! 即使有可能,我也许可以到处走走。

PS:我是.Net / Visual Studio和Sitecore的新手,所以任何帮助表示赞赏

Long story short Client provides us with Smarty Templates on Front end. The .Net port of Smarty (Sharpy) is capable of converting all of those templates and use just like we use RAZOR templates. I am unable to figure out how to switch the templating engine to render the Sharpy files instead of RAZOR files so that the Views need not be converted to RAZOR and avoid a lot of code-rewrite that is happening right now.

What I've tried:

I added “sharpy” as valid extension in Sitecore MVC configuration. I added Sharpy.dll and System.ComponentModel.Composition.dll as reference in the project – required as per the Sharpy documentation. I added view engine in application_start function of global.asax ( ViewEngines.Engines.Add(new SharpyViewEngine()) ); I added view engine in initialization pipeline – to make sure it’s available

Error:

There is no Build Provider registered for the Extension '.sharpy'. You can register one in the section in machine.config or web.config. Make sure is has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'.

I am unable to find the exact cause. Googling did not help much as almost all of the users prefer RAZOR to be used. Also need to know what build provider will be applicable here.

UPDATE: Can I find a post/blog on exactly how it is done. Its okay even if it is some other templating engine! I may be able to get around even if that is available.

P.S.: I am new to both .Net/Visual Studio and Sitecore, so any help appreciated

最满意答案

在Project中创建新的Sitecore初始化管道 - >管道 - >初始化 - > Sharpy.cs,在Process函数中添加你的代码以添加视图引擎ViewEngines.Engines.Add(new SharpyViewEngine())

添加/修改项目配置以使用处理器标记添加新的管道代码

<pipeline><initialize><processor patch:after="processor[@type='Sitecore.Pipeline.Loader.EnsureAnonymousUsers, Sitecore.Kernal']" type="Project.Pienter code herepelines.Initialize.Sharpy, Project.Domain /></initialize></pipeline>

将构建提供程序标记添加到Project的Web配置文件中。

<compilation><buildProviders><add extension=".sharpy" type='System.Web.Compilation.PageBuildProvider"/></buildProviders></compilation>

将Shapry dll文件添加到项目中作为参考。

Sitecore.MVC.Config中添加sharpy作为有效扩展名

<sitecore><settings><setting name="MVC.ViewExtensions" value="|cshtml|sharpy|"/></settings></sitecore>

重建整个项目,发布然后检查。

现在你的系统开始执行Sharpy视图引擎,Sharpy将开始执行.Sharpy文件。

Create new Sitecore initialization Pipeline in Project -> Pipeline -> Initialize -> Sharpy.cs, in the Process function add your code to add view engine ViewEngines.Engines.Add(new SharpyViewEngine())

Add/Modify your project config to add new pipeline code using processor tag

<pipeline><initialize><processor patch:after="processor[@type='Sitecore.Pipeline.Loader.EnsureAnonymousUsers, Sitecore.Kernal']" type="Project.Pienter code herepelines.Initialize.Sharpy, Project.Domain /></initialize></pipeline>

Add build providers tag into the Project's Web config file.

<compilation><buildProviders><add extension=".sharpy" type='System.Web.Compilation.PageBuildProvider"/></buildProviders></compilation>

Add Shapry dll files to your project as reference.

Add sharpy as valid extension in your Sitecore.MVC.Config

<sitecore><settings><setting name="MVC.ViewExtensions" value="|cshtml|sharpy|"/></settings></sitecore>

Rebuild entire project, publish and then check.

Now your system start executing Sharpy view engine, and Sharpy will start executing .Sharpy files.

更多推荐

本文发布于:2023-08-07 04:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1459761.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模板   引擎   Sitecore   Razor   Engine

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!