Skip to content

Instantly share code, notes, and snippets.

@JeffTD
Created August 11, 2017 22:29
Show Gist options
  • Save JeffTD/39f90c84aa3a37d2b0b99304642d2a0a to your computer and use it in GitHub Desktop.
Save JeffTD/39f90c84aa3a37d2b0b99304642d2a0a to your computer and use it in GitHub Desktop.
Use Liquid to capture the slug of a NationBuilder website.
{% assign NationSlug = '' %} <!-- zero out variable at top of page -->
{% capture ThemeURLString %}{{ theme[''] }}{% endcapture %} <!-- capture a dummy theme call which gives us a URL string containing the non-custom domain -->
{% assign url_parts = ThemeURLString | split:'/' %} <br> <!-- split this URL on /'s to extract the domain (aka slug) -->
{% assign SubDomain = url_parts[2] | split:'.' %} <!-- split the subdomain from nationbuilder.com -->
{% if SubDomain[0] contains '-' %} <!-- if subdomain contains hyphen aka if site is not primary site -->
{% assign NationSlugParts = SubDomain[0] | split:'-' %} <!-- split site.slug from nation.slug -->
{% assign NationSlug = NationSlugParts[1] %}
{% else %} <!-- if subdomain doesn't contain hyphen -->
{% assign NationSlug = SubDomain[0] %} <!-- assign subdomain (aka nation slug) as NationSlug variable -->
{% endif %}
NationSlug: {{ NationSlug }}
@JeffTD
Copy link
Author

JeffTD commented Aug 11, 2017

This snippet creates variable called {{ NationSlug }} that is just that - the slug of the nation. It includes a check to see if the site is the primary site or not, and then splits the site.slug off from the nation.slug in the case of non-primary sites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment