Problem with iframe in DIV macro
Asked by jonb:

I am creating a DIV macro that will allow users to place custom \<div\> tags and place content within the div.

I tested with an iframe and i noticed that there are extraneous tags being displayed as plain text after the iframe.

I'm just basing this test on the "collapse" macro from this page: <https://confluence.atlassian.com/conf73/writing-user-macros-991928530.html>

![screenshot_2020-11-12_08.33.13_img.png](/t5/image/serverpage/image-id/118055i5675A1F1BD73665E/image-dimensions/392x249?v=v2 "screenshot_2020-11-12_08.33.13_img.png")

I'm putting the HTML macro with my iframe within my DIV macro.

![screenshot_2020-11-12_08.32.09_img.png](/t5/image/serverpage/image-id/118059i06389C890242EFA6/image-dimensions/759x234?v=v2 "screenshot_2020-11-12_08.32.09_img.png")This is what the rendered page looks like. The iframe is correctly inside my div container, but there is an extra "\</div\>" printed after the iframe

![screenshot_2020-11-12_08.32.27_img.png](https://community.atlassian.com/t5/image/serverpage/image-id/118062iC297647C549F3150/image-size/large?v=v2&px=999 "screenshot_2020-11-12_08.32.27_img.png")

Looking at the page source, the \</div\> is both in the html as expected but also in some text after the iframe.

![screenshot_2020-11-12_08.37.02_img.png](/t5/image/serverpage/image-id/118061i88ECDC54B0539B4A/image-size/large?v=v2&px=999 "screenshot_2020-11-12_08.37.02_img.png")

This becomes even more of a problem if you have nested div macros or tables, it seems to print out any closing tags after the iframe.

I've tested with a few other websites in the iframe with similar results.


Answers:
author: Bill Bailey
body: Why are you nesting a HTML macro inside the body of the macro? I would just structure the macro so that all the HTML is inside the user macro, and then you can either have body hold the src link, or even make it a parameter with no macro body. Then use the parameters in your code.

I would also make the width and height parameters to make it more configurable.

If you need the HTML macro, then move that instance to inside the user macro. Take a look at this article I wrote awhile back on wrapping a macro: [Getting Started with User Macros - Writing a Wrapper Macro](https://community.atlassian.com/t5/Confluence-articles/Getting-Started-with-User-Macros-Writing-a-Wrapper-Macro/ba-p/979571)

comments: author: jonb
body: Thanks for the info Bill, I'll take a look at your article.

The original intent was to have a generic div macro that could include any content like text or other macros. This would help tie in with custom stylesheets and being able to style elements with a surrounding div id/class.

Are there known issues with nested macros?


author: Bill Bailey
body: I think the issue with nested macros is unpredictability with the rendered output. I have always gone the route or wrapping a macro if needed.


author: jonb
body: I see. Yeah I've been trying to generalize macros as best i can and then nest any existing macros inside, but like you said I've also ran into some strange cases of the output not behaving as expected.

I'll try making a simple iframe specific macro and see if that has any similar issues.

For the most part, I haven't had issues with the nested div macros in my post. But seems to be something with how the iframe is processed in conjunction with the macro.


author: jonb
body: Putting the iframe directly in the macro (not using the nested html macro):

*\<div\>\<iframe\>...\</iframe\>\</div\>* still has the issue

Putting just the iframe in the macro seems to work fine.

I will just create an iframe macro and expose some paramters.


Tags: confluence-server

html

iframe

macro

server

user-macro