{# Shortcut variables #} {% set default = mediaembed.config.media %} {% set oembed = mediaembed.service %} {# Processing error #} {% if not mediaembed.success %} {% if default.responsive %} {% set class = "-responsive mediaembed-msod" %} {% else %} {% set class = " mediaembed-msod\" style=\"max-width: " ~ default.width ~ "px;" %} {% endif %}

Unable to process oEmbed media:{{ mediaembed.raw.src|e }}

Error:{{ mediaembed.message }}

{# Setup block #} {% else %} {% set response = oembed.attributes %} {# Normalize response #} {% if (response.width is empty) or not (response.width is defined) or (response.width == 0) %} {% set response = response|merge({'width' : default.width|default(1)}) %} {% endif %} {% if (response.height is empty) or not (response.height is defined) or (response.height == 0) %} {% set response = response|merge({'height' : default.height|default(1)}) %} {% endif %} {% set width = response.width %} {% set height = response.height %} {% set ratio = height / width %} {# Adjust OEmbed media dimensions or restrict them? #} {% if default.adjust %} {# Check if computed height is larger than default setting #} {% if (width * ratio) > default.height or (height / ratio) > default.width %} {# Rescale width and height #} {% set width = default.width|default(1) %} {% set height = (default.width * ratio)|round %} {% endif %} {% else %} {% set width = default.width|default(1) %} {% set height = default.height|default(1) %} {% endif %} {# Recompute aspect ratio #} {% set ratio = height / width %} {% set container_styles = "padding-bottom: " ~ "%.2f"|format(ratio * 100) ~ "%;" %} {# Embed responsive OEmbed media #} {% if default.responsive %} {% set responsive = "-responsive" %} {% set width = 1920 %} {% set height = (width * ratio)|round %} {% else %} {% set styles = " style=\"max-width: " ~ width ~ "px; max-height: " ~ height ~ "px;\"" %} {% endif %} {# Setup lazy loading media for those with preview enabled #} {% if default.preview %} {% set lazyload = " lazyload" %} {% set lazyload_script = " onclick=\"lazyload(this)\"" %} {% endif %}
{# Embed content according to media type #} {# -- Photo -- #} {% if oembed.type == "photo" %} {% set title = oembed.getOembed().provider_name ~ ': “' ~ oembed.title ~ '” by ' ~ oembed.author %} {{ oembed.title }} {# -- Video -- #} {% elseif oembed.type == "video" %} {# JavaScript lazy-loading #} {# Show Thumbnail #} {% if default.preview and oembed.thumbnail %} {{ mediaembed.raw.alt }} {% else %} {# Show placeholder #} {% endif %} {# Toggle for loading iframe content #} {# Implement JavaScript-less lazyload technique #} {# -- Link -- #} {% elseif oembed.type == "link" %} {% set title = oembed.getOembed().provider_name ~ ': “' ~ oembed.mediaembed.raw.title|default(title) ~ '” by ' ~ oembed.author %} {{ mediaembed.raw.src|e }} {# -- Rich media -- #} {% elseif oembed.type == "rich" %}
{{ oembed.getEmbedCode() }}
{# -- Nothing from above -- #} {% else %} {# Show at least a link for the user #} {{ mediaembed.raw.src|e }} {% endif %}
{% endif %}