I am trying to create a reusable component with a set a default variables that can be overridden when included in a template:
includes/social.twig
{% set padding, size, color, hover = '2', '4', 'pink', 'black' %}
<ul>
<li class="px-{{ padding }} text-{{ size }}">
<a class="text-{{ color }} hover:text-{{ hover }}" href="{{ contactDetails.link }}">
<i class="fab fa-link"></i>
</a>
</li>
</ul>
page.twig
{% include '_includes/social-links.twig' with {
padding: '10',
size: '2',
color: 'blue',
} %}
When using this, variables that haven't been set in the include statement would remain as defined in the include file, and those that have would override the variables set in the include file. This doesn't happen - nothing gets overridden.
I can achieve a working version of this using:
includes/social.twig
<ul>
<li class="px-{{ padding }} text-{{ size }}">
<a class="text-{{ color }} hover:text-{{ hover }}" href="{{ contactDetails.link }}">
<i class="fab fa-link"></i>
</a>
</li>
</ul>
page.twig
{% set padding, size, color, hover = '2', '2', 'blue', 'black' %}
{{ include('_includes/social-links.twig') }}
This involves not setting the vars in the include file, but setting them in the page template - this approach seems more error prone and less maintainable than the version I am trying to achieve.