Skip to content

Instantly share code, notes, and snippets.

@jmuspratt
Last active August 29, 2015 14:21
Show Gist options
  • Save jmuspratt/0494aaa48dc216e5d4c1 to your computer and use it in GitHub Desktop.
Save jmuspratt/0494aaa48dc216e5d4c1 to your computer and use it in GitHub Desktop.
Assume we're in a Matrix field called postBody which contains different kinds of blocks. videoBlock has three fields: (1) a dropdown for videoService (youtube vs. vimeo), (2) a dropdown for videoAspectRatio (ratio-16-9, ratio-4-3, etc.), and (3) a text field for videoID.
{% if entry.postBody | length %}
<div class="post-body">
{% for block in entry.postBody %}
{% switch block.type %}
{% case 'textBlock' %}
{{ block.text }}
{# cases for other blocks #}
{% case 'videoBlock' %}
<div class="media-embed {{ block.videoAspectRatio }}">
{% switch block.videoService %}
{% case "youtube" %}
{# see youtube parameters at https://developers.google.com/youtube/player_parameters #}
<iframe class='youtube-player' type='text/html' src='http://www.youtube.com/embed/{{ block.videoID }}?version=3&amp;theme=light&amp;modestbranding=1&amp;rel=0&amp;fs=1&amp;showsearch=0&amp;showinfo=0&amp;iv_load_policy=3&amp;wmode=transparent' frameborder='0' allowfullscreen='true'></iframe>
{% case "vimeo" %}
{# see vimeo parameters at https://developer.vimeo.com/player/embedding #}
<iframe class="vimeo-player" src="https://player.vimeo.com/video/{{ block.videoID }}?title=0&amp;portrait=0&amp;badge=&amp;byline=0&amp;color=dddddd" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
{% endswitch %}
</div> <!-- media-embed -->
{% endswitch %}
{% endfor %}
</div> <!-- post-body -->
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment