[英]Write Tridion dreamweaver identifier as output package
While working on compound page templating project I have discovered very interesting issue. 在处理复合页面模板项目时,我发现了一个非常有趣的问题。 Customer uses ${stringvalue-session-or-something-specific} in their custom developed applications that are saved and rendered in component templates using XSLT.
客户在其定制开发的应用程序中使用$ {stringvalue-session-or-something-specific} ,使用XSLT将其保存并呈现在组件模板中。 When try to render the component presentations containing reserved Tridion dreamweaver identifier (${}) I have got Template Builder error similar to
当尝试渲染包含保留的Tridion Dreamweaver标识符($ {})的组件演示文稿时,我遇到类似于Template Builder的错误
JScriptException: Expression '""["scopedTarget.personalia"]."" != ""' had error 'Expected identifier' at Tridion.ContentManager.Templating.Expression.JScriptEvaluator.EvaluateToObject(String statement) at Tridion.ContentManager.Templating.Expression.JScriptEvaluator.EvaluateToString(String statement)
JScriptException:表达式'“” [“ scopedTarget.personalia”]。“”!=“”'在Tridion.ContentManager.Templating的Tridion.ContentManager.Templating.Expression.JScriptEvaluator.EvaluateToObject(String语句)发生错误“ Expected identifier”。 Expression.JScriptEvaluator.EvaluateToString(String语句)
Removing and replacing this identifiers is not solution acceptable by customer. 客户不接受删除和替换此标识符的解决方案。 I was wondering what can be the best solution to cope this issue?
我想知道解决这个问题的最佳解决方案是什么? Either using C# code to rendering component presentations, maybe create some custom rewrites( if it is possible because I got error from component presentations).
要么使用C#代码来呈现组件演示文稿,要么创建一些自定义重写(如果可能,因为我从组件演示文稿中出错了)。
A similar thing happens if customers use JSP EL in their applications, which use the same ${...}
syntax, and want to encapsulate this in their templates. 如果客户在应用程序中使用JSP EL(使用相同的
${...}
语法)并将其封装在模板中,则会发生类似的情况。
The most common solution is to replace this syntax with something like $[...]
in the Dreamweaver templates and use a .Net TBB after the Dreamweaver template which uses string replacement or regular expressions to convert it. 最常见的解决方案是使用Dreamweaver模板中的
$[...]
替换此语法,并在Dreamweaver模板之后使用.Net TBB ,该模板使用字符串替换或正则表达式进行转换。
See my gist for an example TBB that does this. 请参阅我的要点以获取执行此操作的示例TBB。
I normally use this code to "enable JSTL in templates". 我通常使用此代码“在模板中启用JSTL”。 Since you can't change Tridion to use a different code identifier, you need to change your markup.
由于您无法将Tridion更改为使用其他代码标识符,因此需要更改标记。 Run this TBB at the END of your template to convert
$[expression]
to ${expression}
在模板末尾运行此TBB,将
$[expression]
转换为${expression}
using System;
using System.Text.RegularExpressions;
using Tridion.ContentManager.Templating;
using Tridion.ContentManager.Templating.Assembly;
namespace TridionTemplates
{
[TcmTemplateTitle("Enable JSTL")]
public class EnableJSTL : ITemplate
{
private static readonly Regex JstlRegex = new Regex(@"\$\[.*\]");
public void Transform(Engine engine, Package package)
{
Item outputItem = package.GetByName(Package.OutputName);
string outputText = outputItem.GetAsString();
Match match = JstlRegex.Match(outputText);
while (match.Success)
{
String replaceJstl = match.Value.Replace("[", "{");
replaceJstl = replaceJstl.Replace("]", "}");
outputText = outputText.Replace(match.Value, replaceJstl);
match = match.NextMatch();
}
outputItem.SetAsString(outputText);
package.Remove(outputItem);
package.PushItem(Package.OutputName, outputItem);
}
}
}
如果您绝对不能更改Dreamweaver模板中的语法(如我所述,我不确定我是否完全理解/同意这样做的原因),那么也许可以改为使用Razor介体进行模板制作?
As I mentioned replacing syntax is not solution. 正如我提到的,替换语法不是解决方案。 I have solved this by rendering component presentation in separate C# tbb before Dreamweaver template.
我已经通过在Dreamweaver模板之前的单独C#tbb中呈现组件演示文稿来解决了此问题。 Off course,David suggestion is useful if you are allowed to change the syntax.
当然,如果允许您更改语法,David建议会很有用。
I use SDL Tridion 2011 SP1 HR1. 我使用SDL Tridion 2011 SP1 HR1。 TemplateBuilder version 6.1 Build 6.1.0.73.
TemplateBuilder版本6.1 Build 6.1.0.73。 Extract components from Page executed before DWT code below.
从下面的DWT代码之前执行的Page中提取组件。
<!-- TemplateBeginRepeat name="Components" -->
@@RenderComponentPresentation()@@ @@ RenderComponentPresentation()@@
<!-- TemplateEndRepeat -->
Output error logged from Template builder in case if component presentations contains ${sometext}. 如果组件演示文稿包含$ {sometext},则从“模板”构建器记录输出错误。
JScriptException: Expression '""["scopedTarget.personalia"]."" != ""' had error 'Expected identifier' at Tridion.ContentManager.Templating.Expression.JScriptEvaluator.EvaluateToObject(String statement) at Tridion.ContentManager.Templating.Expression.JScriptEvaluator.EvaluateToString(String statement) at Tridion.ContentManager.Templating.Package.EvaluateExpression(String expression) at Tridion.ContentManager.Templating.Dreamweaver.DreamweaverMediator.TransformValueReferences(Package package, StringReference templateReference, Regex startTagExpression, String endTag) at Tridion.ContentManager.Templating.Dreamweaver.DreamweaverMediator.TransformRegions(Package package, String dreamweaverTemplate) at Tridion.ContentManager.Templating.Dreamweaver.DreamweaverMediator.Transform(Engine engine, Template templateToTransform, Package package) at Tridion.ContentManager.Templating.Engine.ExecuteTemplate(Template template, Package package) at Tridion.ContentManager.Templating.Engine.InvokeTemplate(P
JScriptException:Expression'“”[“scopedTarget.personalia”]。“”!=“”'在Tridion.ContentManager.Templating的Tridion.ContentManager.Templating.Expression.JScriptEvaluator.EvaluateToObject(String语句)中出现错误'Expected identifier'。 Tridion的Tridion.ContentManager.Tempaging.Dreamweaver.DreamweaverMediator.TransformValueReferences(包包,StringReference templateReference,Regex startTagExpression,String endTag)中的Tridion.ContentManager.Templating.Package.EvaluateExpression(String表达式)中的Expression.JScriptEvaluator.EvaluateToString(String语句) .ContentManager.Templating.Dreamweaver.DreamweaverMediator.TransformRegions(包package,String dreamweaverTemplate)在Tridion.ContentManager.Templating.Dreamweaver.DreamweaverMediator.Transform(Engine engine,Template templateToTransform,Package package)的Tridion.ContentManager.Templating.Engine.ExecuteTemplate(模板模板,打包程序包)位于Tridion.ContentManager.Templating.Engine.InvokeTemplate(P ackage package, TemplateInvocation templateInvocation, Template template) at Tridion.ContentManager.Templating.Compound.CompoundTemplateMediator.Transform(Engine engine, Template templateToTransform, Package package) at Tridion.ContentManager.Templating.Engine.ExecuteTemplate(Template template, Package package) at Tridion.ContentManager.Templating.Engine.InvokeTemplate(Package package, TemplateInvocation templateInvocation, Template template) at Tridion.ContentManager.Templating.Engine.TransformPackage(Template template, Package package) at Tridion.ContentManager.Templating.Debugging.DebuggingEngine.Run() at Tridion.ContentManager.Templating.Debugging.DebugSession.Run() ---Caused by: Expected identifier eval code: Line 1 - Error: Expected identifier
Tridion的Tridion.ContentManager.Templating.Engine.ExecuteTemplate(模板模板,包软件包)中的Tridion.ContentManager.Templating.Compound.CompoundTemplateMediator.Transform(Engine engine,Template templateToTransform,Package package)的ackage包,TemplateInvocation templateInvocation,Template template位于Tridion.ContentManager.Templating.Debugging.DebuggingEngine.Run()的Tridion.ContentManager.Templating.Engine.TransformPackage(模板模板,包软件包)中的.ContentManager.Templating.Engine.InvokeTemplate(包软件包,TemplateInvocation templateInvocation,模板模板) Tridion.ContentManager.Templating.Debugging.DebugSession.Run()---引起:预期的标识符eval代码:第1行 - 错误:预期的标识符
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.