Created
July 24, 2018 12:08
-
-
Save davidhellmann/407c7b0cec475d010d1aa3ddc046776d to your computer and use it in GitHub Desktop.
Craft CMS 3 Nav with Macros
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
{ | |
"fieldGroups": [ | |
"Globals" | |
], | |
"fields": [ | |
{ | |
"group": "Globals", | |
"name": "Nav Main", | |
"handle": "globalNavMain", | |
"instructions": "", | |
"type": "craft\\fields\\Matrix", | |
"minBlocks": "", | |
"maxBlocks": "", | |
"localizeBlocks": "1", | |
"blockTypes": [ | |
{ | |
"name": "Menu Item", | |
"handle": "menuItem", | |
"fields": [ | |
{ | |
"required": false, | |
"translationMethod": "site", | |
"name": "Menu Item", | |
"handle": "menuItem", | |
"instructions": "", | |
"type": "typedlinkfield\\fields\\LinkField", | |
"typesettings": { | |
"allowCustomText": "1", | |
"allowedLinkNames": [ | |
"url", | |
"category", | |
"entry" | |
], | |
"allowTarget": "1", | |
"defaultLinkName": "url", | |
"defaultText": "", | |
"typeSettings": { | |
"url": { | |
"disableValidation": "1" | |
}, | |
"email": { | |
"disableValidation": "" | |
}, | |
"tel": { | |
"disableValidation": "" | |
}, | |
"asset": { | |
"sources": "*" | |
}, | |
"category": { | |
"sources": "*" | |
}, | |
"entry": { | |
"sources": "*" | |
} | |
} | |
} | |
}, | |
{ | |
"required": false, | |
"name": "Visible", | |
"handle": "visible", | |
"instructions": "", | |
"type": "craft\\fields\\Lightswitch", | |
"typesettings": { | |
"default": "" | |
} | |
}, | |
{ | |
"required": false, | |
"translationMethod": "site", | |
"name": "Highlight Triggers", | |
"handle": "highlightTriggers", | |
"instructions": "Please do not edit this field. It's needed for development stuff. ", | |
"type": "craft\\fields\\PlainText", | |
"typesettings": { | |
"placeholder": "\u2014", | |
"code": "", | |
"multiline": "", | |
"initialRows": "4", | |
"charLimit": "", | |
"columnType": "text" | |
} | |
}, | |
{ | |
"required": false, | |
"name": "Segment Position", | |
"handle": "segmentPosition", | |
"instructions": "", | |
"type": "craft\\fields\\Number", | |
"typesettings": { | |
"decimals": 0 | |
} | |
}, | |
{ | |
"required": false, | |
"name": "Icon Name", | |
"handle": "iconName", | |
"instructions": "", | |
"type": "craft\\fields\\PlainText", | |
"typesettings": { | |
"placeholder": "", | |
"code": "", | |
"multiline": "", | |
"initialRows": "4", | |
"charLimit": "", | |
"columnType": "text" | |
} | |
} | |
] | |
} | |
] | |
} | |
], | |
"globalSets": [ | |
{ | |
"name": "Nav Main", | |
"handle": "navMain", | |
"fieldLayout": { | |
"Content": [ | |
"globalNavMain" | |
] | |
} | |
} | |
] | |
} |
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
{# @var craft \craft\web\twig\variables\CraftVariable #} | |
{# @var entry \craft\elements\Entry #} | |
{# | |
Set Active Class | |
------------------------------------------------------------ | |
{% import '_partials/macros/_macro-isActive.html' as macroIsActive %} | |
{{ macroIsActive.isActive('news', -1, 'cn') }} | |
#} | |
{% macro isActive(segments, position, prefix, cn) %} | |
{% spaceless %} | |
{% set segments = segments | default(null) %} | |
{% set position = position | default(-1) %} | |
{% set prefix = prefix | default(null) %} | |
{% set cn = cn | default('is-active') %} | |
{% if segments is iterable and craft.app.request.getSegment(position) in segments %} | |
{{ prefix ? prefix ~ cn : cn }} | |
{% elseif craft.app.request.getSegment(position) == segments %} | |
{{ prefix ? prefix ~ cn : cn }} | |
{% endif %} | |
{% endspaceless %} | |
{% endmacro %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment