Handling the Syntax Clash of Tridion DWT and JSP Expression Language

JSP Expression Language has the same syntax as Tridion’s Dreamweaver field rendering syntax.  So when you try to render JSP EL in your DWT, the Dreamweaver Mediator replaces it with a blank because it can’t successfully resolve it.  Here is a quick tip on how to get around this problem.

Let’s start off with an example DWT which is part of a template for an ‘include’ page (a header page in my case), and this include page takes an input parameter from it’s parent page which we want to render using JSP EL:

Calling page:

<!-- TemplateBeginIf cond="HeaderPath && HeaderPath!='none'" -->
    <jsp:include page="@@HeaderPath@@">
        <jsp:param name="canonicalUrl" value="@@PagePublishUrl@@" />
<!-- TemplateEndIf -->

and a snippet on the include page which renders a custom tag:

<nav:mainNavigation pagePublishUrl="${param.pagePublishUrl}" />

Well, good ol’ Dreamweaver will try to resolve this EL syntax “${param.pagePublishUrl}” and replace it with an empty string.

So to work around this issue, we escape the JSP EL code with backslashes and utilize a TBB to un-escape it once Dreamweaver finishes it’s deeds.

So the DWT would now look as follows:

<nav:mainNavigation pagePublishUrl="\$\{param.pagePublishUrl\}" />

This TBB should be placed as the very last TBB in a template and should not be executed twice, i.e. first by a component template and then a page template.

    [TcmTemplateTitle("JSP EL Escape Replacer")]
    public class JspElEscapeReplacer : TemplateBase
        public override void Transform(Engine engine, Package package)
            Initialize(engine, package);
            //This should be placed at Page Template level, otherwise the Page DWT will try to resolve the EL.
            if (package.GetValue(Package.PageName) == null || !this.GetComponentTemplate().IsRepositoryPublishable)
                throw new Exception("This TBB should be used only on a Page Template or Dynamic Component Template.");
            string output = package.GetValue(Package.OutputName);
            output = output.Replace(@"\$\{", "${");
            output = output.Replace(@"\}", "}");
            package.PushItem(Package.OutputName, package.CreateHtmlItem(output));

P.S. Use Will’s TemplateBase available on SDLTridionWorld to speed up TBB development like I’ve done above

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>