Skip to content

Instantly share code, notes, and snippets.

@brianlarson
brianlarson / _macros.twig
Created March 29, 2021 11:33
Get YouTube or VImeo embed from URL
{# get video embed - supports vimeo and youtube #}
{# youtube id - https://supergeekery.com/blog/extracting-a-youtube-id-from-a-url-with-twig #}
{%- macro videoEmbed(url) -%}
{%- if 'youtu' in url -%}
{% set ytregex1 = '/^(?:https?:\\/\\/)?(?:www\.)?(?:youtu\.be\\/|youtube\.com)(?:\\/embed\\/|\\/v\\/|\\/watch\\?v=||\\/watch\\\?.+&v=)/' %}
{% set ytregexTrailingSlash = '/(\\/)$/' %}
{% set ytregexTrailingVariables = '/(&+.*)/' %}
{% set id = url | replace(ytregex1, '') | replace(ytregexTrailingSlash, '') | replace(ytregexTrailingVariables, '') %}
<iframe src="https://www.youtube.com/embed/{{ id }}?autoplay=0&rel=0&modestbranding=1&playsinline=1&rel=0" width="1920" height="1080" frameborder="0" allowfullscreen uk-responsive uk-video="autoplay: false;"></iframe>
{%- elseif 'vimeo' in url -%}
@brianlarson
brianlarson / *.twig
Last active March 29, 2021 11:36
Section entry URI format supporting hierarchical categories field
products/{% if productCategory %}{% for cat in productCategory %}{{ cat.slug }}/{% endfor %}{% else %}/{% endif %}{slug}
@brianlarson
brianlarson / freeform-admin-email-notification.html
Last active December 16, 2020 19:20
Freeform (Craft CMS) Admin Email Notification
<style type="text/css">
body {
font: normal 12px sans-serif;
}
thead {
border-top: 1px solid #353535;
border-right: 1px solid #353535;
border-left: 1px solid #353535;
text-transform: uppercase;
letter-spacing: 1px;