Iframe Tag HTML Objects

When you are working with iframes in your templates you will usually be working with an HTML Object. The following attribute types generate an iframe in their output. 

The purpose of the HTML Object is to allow you to add or change the attributes for the iframe tag before outputting the tag. Instead of having to manually build out the iframe tag just to set a custom id or class value, you can set the attribute value and then simply output the tag. This helps with readability and is often easier to write.

Instead of doing this:

<iframe src="{{ iframe.src }}" class="myIframe" frameborder="0" height="{{ iframe.height }}" width="{{ iframe.width }}" allowfullscreen></iframe>

now you can set the class and then simply output the code:

{% set iframe.class = 'myIframe' %}
{{ iframe.tag }}

Available iframe attributes

At minimum the following iframe attributes are available for you to set or change values:

  • height
  • src
  • width

You can also set any valid HTML attribute on the iframe tag such as 'class', 'id', 'title' or 'data' attributes.

{% set iframe.id = 'iframeid' %}
{% do iframe.set('data-custom', 'Data value') %}

See HTML Objects for more information about setting attribute values.