How to load a widget in an iframe?

The goal is to create a widget like the OOTB HTML Widget but have it render content within an iframe.  It is possible to do that with the JS code to inject content into an iframe, but that has it's own set of issues. I'm just wondering if there is an easier way.

I looked at something like $core_v2_widget.GetFileUrl('frame.vm') as the frame source, but this appears to just point to CFS.

Any ideas?

Thanks.

Parents
  • This should be straightforward. At minimum, you'd probably want the widget's main content to render the host <iframe> and then a separate attachment vm to render the content within the iframe. So, you'd probably want something like:

    <iframe src="$core_v2_encoding.HtmlAttributeEncode($core_v2_widget.GetExecutedFileUrl('content.vm'))"></iframe>

    And then in content.vm, treat it as a normal velocity script which is executed. If the goal is similar to generic content, it could basically output content defined by the widget's configuration.

    The trick here is to use GetExecutedFileUrl instead of GetFileUrl. When that URL is requested, it returns the result of executing the script instead of the URL of the script, itself. As an aside, this is also the primary way in which to provide custom callbacks, as used in many widgets.

Reply
  • This should be straightforward. At minimum, you'd probably want the widget's main content to render the host <iframe> and then a separate attachment vm to render the content within the iframe. So, you'd probably want something like:

    <iframe src="$core_v2_encoding.HtmlAttributeEncode($core_v2_widget.GetExecutedFileUrl('content.vm'))"></iframe>

    And then in content.vm, treat it as a normal velocity script which is executed. If the goal is similar to generic content, it could basically output content defined by the widget's configuration.

    The trick here is to use GetExecutedFileUrl instead of GetFileUrl. When that URL is requested, it returns the result of executing the script instead of the URL of the script, itself. As an aside, this is also the primary way in which to provide custom callbacks, as used in many widgets.

Children