Skip to content

elfacht/craft-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!

About

A collection of useful Craft CMS macros and components.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published