Whats the best way to approach this in twig? So I have a component that is used in multiple places, so within this component I set some default classes like so:
{% set navSidebarClasses = {
heading: 'font-semibold text-lead mb-3',
navList: 'text-sm ml-2',
navItem: '',
navLink: 'text-brand-900 hover:underline inline-flex justify-between items-center py-2',
active: 'font-bold py-2 flex items-center',
parentLink: 'mt-3 pt-6 border-t border-gray-200 font-bold hover:underline inline-flex justify-between items-center'
} %}
However, I want to be able to also pass in some additional classes based on the components context, so these classes would be set on the parent where the component is included. How can/should I setup and pass/merge additional classes into the component. I seem to hit this quite often and so I am looking for a better/improved bullet proof way to do this.
Parent 1
{% set navSidebarClasses = {
navLink: 'hover:text-business-500',
active: 'text-business-500',
parentLink: 'text-business-600'
} %}
{% include '_includes/nav/nav-sidebar-services.twig' with {
navSidebarClasses: navSidebarClasses
} %}
Parent 2
{% set navSidebarClasses = {
navLink: 'hover:text-family-500',
active: 'text-family-500',
parentLink: 'text-family-800'
} %}
{% include '_includes/nav/nav-sidebar-services.twig' with {
navSidebarClasses: navSidebarClasses
} %}