Question

In Tridion I have a page to which a component is attached that has a text field in which, there is a iframe tag like <iframe src="http://mysite.com/l/5042/2012-06-21/9pb4y" width="100%" height="500" frameborder="0" style="border: 0" > </iframe>. I ensure that this tag remains as it is while being processed by C# & DWT template building blocks. But at the end when the page is published, in the source of the page, the tag changes to <iframe src="http://mysite.com/l/5042/2012-06-21/9pb4y" width="100%" height="500" frameborder="0" style="border: 0" />. Due to this the page source does not show any content after the iframe tag. So any component that is attached to the page after the component containing iframe tag does not show up on page. Any idea why the closing tag </iframe> is replaced by self closing tag />?

Was it helpful?

Solution

As Frank mentioned you could use the Convert XML to HTML TBB

(OR)

You could also consider the solution from Chris provided in this thread. Creating anchor links in rich text fields with SDL Tridion 2011 SP1

You apply xslt for the schema field definition. While the TBB option applies to the full CT/PT depending on where you use it, but with XSLT you can use it at the field level and also gets the same format when you use the CoreService for any other use cases.

OTHER TIPS

I asked about this issue, and Jamie Santos helped me with this solution.

I was already using Convert XML to HTML TBB, but this didn't work because the closing tag was already placed in the output variable.

So, the following TBB uses a parameter Schema [Tags] where we pass a list of tags (Comma Separated) we want to change the self closing tag ( e.g. />) with the Closing tag (e.g. )


    [TcmTemplateTitle("Remove Selft Closing Tag")]
    public class RemoveSelfClosingTag : ITemplate
    {
        public override void Transform(Engine engine, Package package)
        {
            var outputItem = package.GetByName(Package.OutputName);

        //if not  Output in package, return
        if (outputItem == null) return;

        var output = outputItem.GetAsString();
        var tagsCsv = package.GetValue("Tags"); //TBB parameter [tags using CSV] : 'iframe'
        if (string.IsNullOrEmpty(tagsCsv)) return;

        var tags = tagsCsv.Split(',');
        foreach (var tag in tags)
        {
            RemoveSelftTag(tag, ref output);
        }
        outputItem.SetAsString(output);
    }

    //ref because string is immutable.
    private void RemoveSelftTag(string tagName, ref string output)
    {
        var pattern = string.Format("(?'fistPart'<(?'tag'{0})[^>]+?)/>", tagName);
        output = Regex.Replace(output, pattern, @"${fistPart}></${tag}>");
    }
}

I think this is due to the "Clean Up" TBB. I would try placing an "empty" space between the tags, something like this:

<iframe src="YOUR_URL_HERE" width="100%" height="500" frameborder="0" style="border: 0" > &nbsp;</iframe>

That should keep the markup untouched and will display the iframe with its closing tag.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top