Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 1.02 KB

README.md

File metadata and controls

39 lines (28 loc) · 1.02 KB

Craft CMS Macros and Components

A collection of Craft CMS macros and components I frequently use on projects. Feel free to use, alter and extend. Suggestions are welcome.

How to use macros

I usually set the macro include in a first level template like _router.html from where I delegated all my pages and set macrosas a parameter on includes:

{# _router.html or another first level template #}
{% set macros = 'partials/_/_macros.html' %}
{% set notfound = '404' %}

{% include ['pages/' ~ entry.type.handle, notfound] with { macros: macros } %}

In the page template I just import the macros and inherit it to the components:

{# page.html #}
{% import macros as helper %}

{# Macro: macros/include.twig #}
{{helper.include('modules', 'hero', {
	image: entry.image.one() ?? null,
	macros: macros
})}}

The _macros.html or .twig:

{% macro myMacro(param) %}
{# Do something here #}
{% endmacro %}

License

Itsa MIT!