Created
          August 11, 2017 22:29 
        
      - 
      
 - 
        
Save JeffTD/39f90c84aa3a37d2b0b99304642d2a0a to your computer and use it in GitHub Desktop.  
    Use Liquid to capture the slug of a NationBuilder website.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | {% 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 }} | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
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.