Last active
November 12, 2019 23:16
-
-
Save xavianaxw/9078ca4fec92767cd8c3cf2493e510c7 to your computer and use it in GitHub Desktop.
Hubspot | getQueryParam() | Passing classes to menu item from Dashboard
This file contains 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
{# Helpers: getQueryParam #} | |
{# Returns the query value by handle #} | |
{# Parameters #} | |
{# url | URL | Required #} | |
{# parameter | Parameter name | Required #} | |
{# How to import this macro to my module #} | |
{# {% from 'NOW_002_Website/helpers/get-query-param.html' import getQueryParam %} #} | |
{# How to use this macro #} | |
{# {{ getQueryParam('http://www.honestfox.com.au?class=custom', 'class') }} #} | |
{# How to check if value is returned by macro #} | |
{# if (getQueryParam('http://www.honestfox.com.au?class=custom', 'class') != '') {} #} | |
{%- macro getQueryParam(url, handle) -%} | |
{%- set urlParts = url | split('?') -%} | |
{%- if urlParts | length > 0 -%} | |
{%- set urlParams = urlParts | last | split('&') -%} | |
{%- if urlParams | length == 0 -%} | |
{%- set urlParams = [urlParams] -%} | |
{%- endif -%} | |
{%- for param in urlParams -%} | |
{%- if param is string_containing handle ~ '=' -%} | |
{{ param | split('=') | last }} | |
{%- endif -%} | |
{%- endfor -%} | |
{%- endif -%} | |
{%- endmacro -%} |
This file contains 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
{% from [filepath] import getQueryParam %} | |
{# check if has '?class' query param to add special classes for styling #} | |
{% set childClass = getQueryParam(child.url, 'class') %} | |
<li class="{{ childClass }}"> | |
{# regex is to remove '?class=' from url #} | |
<a href="{{ child.url | regex_replace('class=' ~ childClass, '') | regex_replace('[?]', '') }}" | |
target="{{ child.linkTarget }}" | |
> | |
{{ child.label }} | |
</a> | |
</li> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment