iframe tag in component gives incomplete page on publishing
Asked Answered
P

3

6

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 />?

Pinebrook answered 23/6, 2012 at 11:6 Comment(2)
Are you sure the "Convert XML to HTML" TBB is present in your Default Finish Actions? That TBB is normally supposed to convert the XML notation back to HTML that older browser prefer.Romany
Yes Convert XML to HTML TBB is present in Default Finish Actions.Pinebrook
I
6

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.

Ipsambul answered 23/6, 2012 at 16:29 Comment(2)
Your link was useful. Currently I am using an empty div tag to suppress this weird behavior like this- <iframe src="http://mysite.com/l/5042/2012-06-21/9pb4y" width="100%" height="500" frameborder="0" style="border: 0" ><div class="empty"></div></iframe>Pinebrook
Your workaround may be solving your problem, but as per html standard you should not use any other tags in iframe tag.Ipsambul
I
1

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}>");
    }
}

Iila answered 27/6, 2014 at 17:47 Comment(0)
S
0

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.

Sottish answered 27/6, 2014 at 14:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.