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.

Revisions

  1. JeffTD created this gist Aug 11, 2017.
    11 changes: 11 additions & 0 deletions capture_nation_slug
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    {% 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 }}