Skip to content

Instantly share code, notes, and snippets.

@apsolut
Last active September 4, 2024 17:31
Show Gist options
  • Save apsolut/becba83256a304934ff6df4a5fb19d2f to your computer and use it in GitHub Desktop.
Save apsolut/becba83256a304934ff6df4a5fb19d2f to your computer and use it in GitHub Desktop.
hubspot youtube get ID
{# Function to extract YouTube video ID #}
{% macro extract_youtube_id(url) %}
{% set cleaned_url = url|trim %}
{% set video_id = cleaned_url
| replace("https://www.youtube.com/watch?v=", "")
| replace("http://www.youtube.com/watch?v=", "")
| replace("https://youtu.be/", "")
| replace("http://youtu.be/", "")
| split("&")
| first
| split("?")
| first %}
{# Validate the extracted ID #}
{% if video_id|length == 11 %}
{{ video_id }}
{% else %}
{{ "" }}
{% endif %}
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment