File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -716,6 +716,31 @@ To tell the system that ``icon`` and ``type`` are props and not attributes, use
716716 {% endif %}
717717 </button>
718718
719+ You can specify mandatory and optional props:
720+
721+ .. code-block :: html+twig
722+
723+ {# templates/components/Button.html.twig #}
724+ {% props icon, type = 'primary' %}
725+
726+ <button {{ attributes.defaults({class: 'btn btn-'~type}) }}>
727+ {% block content %}{% endblock %}
728+ <span class="fa-solid fa-{{ icon }}"></span>
729+ </button>
730+
731+ Examples of usage:
732+
733+ .. code-block :: html+twig
734+
735+ {# property "icon" is missing, an exception is thrown #}
736+ <twig:Button>Share</twig:Button>
737+
738+ {# property "icon" is passed, property "type" use its default value "primary" #}
739+ <twig:Button icon="share">Share</twig:Button>
740+
741+ {# both properties "icon" and "type" are passed #}
742+ <twig:Button icon="share" type="secondary>Share</twig:Button>
743+
719744.. _embedded-components :
720745
721746Passing HTML to Components Via Blocks
You can’t perform that action at this time.
0 commit comments