Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tridion: Dreamweaver doesn't resolves the HTML code field

We have a compound CT, which outputs the code field of one of the component.

The dream-weaver part of CT is as follows:

<!-- TemplateBeginRepeat name="Component.HTMLCode" -->
    @@Component.HTMLCode@@
<!-- TemplateEndRepeat -->

However this CT displays the code field on the page, instead of converting into HTML.

For eg: If the code field has a value as -> <div align="center" id="loginapp"></div> Then this same value is displayed on page instead of parsing.

In the page source, we get output as "&lt ;div align=&quot ;center" id=&quot ;loginapp&quot ;&gt ;&lt ;/div&gt ;"

I know this can be resolved if we use C#. But is there any way using dreamweaver to stop the conversion of special characters?

like image 302
Huston Lopes Avatar asked Dec 12 '22 22:12

Huston Lopes


2 Answers

You should use dwt to publish the code to server, I mean create new dwt for every code and just paste the code in the dwt. you can use this dwt with emply component or resource type component.

or if you want to use text field, try following tbb code. add this tbb at the end of the template.

public override void Transform(Engine engine, Package package)
    {


        Regex objExp = new Regex(@"&#\d+;", RegexOptions.IgnoreCase);
        Regex objDecExp = new Regex(@"[^0-9]", RegexOptions.IgnoreCase);

        this.Initialize(engine, package);
        string strPackage = package.GetValue("Output");

        strPackage = unescapeHTML(strPackage);

        strPackage = objExp.Replace(strPackage, delegate (Match match)
        {

            string strInput = match.ToString();
            strInput = objDecExp.Replace(strInput, "");


            int intValue = Convert.ToInt32(strInput);
            char strChar = (char)intValue;

            return strChar.ToString();
        });



        strPackage = strPackage.Trim();

        Item objOutput = package.CreateStringItem(ContentType.Html, strPackage);
        package.PushItem("Output", objOutput);

    }

    private string unescapeHTML(string strInput)
    {
        StringBuilder strOutput = new StringBuilder(strInput);
        strOutput.Replace("&quot;", "&#34;");
        strOutput.Replace("&nbsp;", "&#32;");
        strOutput.Replace("&amp;", "&#38;");
        strOutput.Replace("&apos;", "&#39;");
        strOutput.Replace("&lt;", "&#60;");
        strOutput.Replace("&gt;", "&#62;");
        strOutput.Replace("&iexcl;", "&#161");
        strOutput.Replace("&cent;", "&#162");
        strOutput.Replace("&pound;", "&#163");
        strOutput.Replace("&curren;", "&#164");
        strOutput.Replace("&yen;", "&#165");
        strOutput.Replace("&brvbar;", "&#166");
        strOutput.Replace("&sect;", "&#167");
        strOutput.Replace("&uml;", "&#168");
        strOutput.Replace("&copy;", "&#169");
        strOutput.Replace("&ordf;", "&#170");
        strOutput.Replace("&not;", "&#172");
        strOutput.Replace("&shy;", "&#173");
        strOutput.Replace("&reg;", "&#174");
        strOutput.Replace("&macr;", "&#175");
        strOutput.Replace("&deg;", "&#176");
        return strOutput.ToString();    
    }


}
like image 106
vikas kumar Avatar answered Dec 24 '22 11:12

vikas kumar


If I recall correctly it is depending on your fieldtype, if in your Schema you use a normal text field, then HTML is escaped, if you use a rich text field, it will be resolved.

An option would perhaps be to write a Dreamweaver Custom function which allows you to unescape the field (represent it as an HTML field rather than a text field). As you mentioned you could also do it in a TBB, but the Dreamweaver Custom Functions are directly callable from the DWT Template. Either way I think you indeed need to do some coding yourself.

like image 37
Bart Koopman Avatar answered Dec 24 '22 13:12

Bart Koopman