Control Flow with `include`

#1

Hello,

I’m trying to create a YouTube embedder using include as described in Adding YouTube Embed Video Plugin.

This is the youtube-embedder.html I craeted:

{% if include.class %}
	<iframe class="{{ include.class }}" width="{{ include.width }}" height="{{ include.height }}" src="https://www.youtube.com/embed/{{ include.id }}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
{% else %}
	<iframe width="{{ include.width }}" height="{{ include.height }}" src="https://www.youtube.com/embed/{{ include.id }}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
{% endif %}

Basically I want to enter the class if it is defined in the include and nothing if it is not.
This is how I use it:

{% include youtube-embed.html id=tbUB7NWAtHw width=960 height=540 class="center-iframe" %}

Yet it doesn’t work.

What is wrong with the Control Flow I created?

0 Likes

#2

I think I got it.
The problem is kramdown parses this as MarkDown code.
Hence the Tab I added before <iframe...> made it interpret it as a code.

By the way, should it be:

{% include youtube-embed.html id=tbUB7NWAtHw width=960 height=540 class="center-iframe" %}

Or

{% include youtube-embed.html id=tbUB7NWAtHw width=960 height=540 class=center-iframe %}

Note: Mind the missing " in the the class=center-iframe of the 2nd example.

Should I add "? Because it works only if I add " but then I don’t understand why it is not required for the id (If it is for strings) or the numerical values (I guess numerical values doesn’t need it)?

What are the rules?

0 Likes