craft helper
1.0.0
คอลเลกชันของแมโคร CMS และส่วนประกอบที่ฉันใช้บ่อยในโครงการ อย่าลังเลที่จะใช้เปลี่ยนแปลงและขยาย ยินดีต้อนรับข้อเสนอแนะ
ฉันมักจะตั้งค่าแมโครรวมอยู่ในเทมเพลตระดับแรกเช่น _router.html จากที่ฉันมอบหมายหน้าทั้งหมดของฉันและตั้งค่า macros เป็นพารามิเตอร์รวมถึง:
{# _router.html or another first level template #}
{% set macros = ' partials/_/_macros.html ' %}
{% set notfound = ' 404 ' %}
{% include [ ' pages/ ' ~ entry . type . handle , notfound ] with { macros : macros } %}ในเทมเพลตหน้าฉันเพิ่งนำเข้ามาโครและสืบทอดไปยังส่วนประกอบ:
{# page.html #}
{% import macros as helper %}
{# Macro: macros/include.twig #}
{{helper. include ( ' modules ' , ' hero ' , {
image : entry . image . one () ?? null ,
macros : macros
})}} _macros.html หรือ. twig:
{% macro myMacro( param ) %}
{# Do something here #}
{% endmacro %}Itsa MIT!