Add Twig switch/case extension #6
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new switch/case extension to Twig allowing for switch/case from within templates.
This PR fixes/implements the following bugs/features
README.mdwith documentation on how to use this new featureExplain the motivation for making this change. What existing problem does the pull request solve?
Continue adding new functionality to Emulsify Tools.
Documentation update (required)
Yes.
README.mdwas updated with new information also copied here for eventual inclusion on the Emulsify website:This adds the ability to do a
switch/casefunction from within Twig templates. To use:{% switch content.field_name.0 %} {% case "text" %} <p>This appears if the field name value is set to "text"</p> {% case "image" %} <p>This appears if the field name value is set to "image"</p> {% default %} <p>The field text did not match any case.</p> {% endswitch %}Note that the
switch,endswitch, andcasetags are required and thedefaultis optional.How to review this pull request
composer.jsonrepositoriessection:{ "type": "vcs", "url": "https://github.com/emulsify-ds/emulsify_tools.git" }emulsify_toolsthat are already therecomposer require emulsify-ds/emulsify_tools --prefer-sourceemulsify_toolsnow residesgit checkout switch-caseemulsify_toolsis installed{% set variable_name = "item 1" %} {% switch variable_name %} {% case "item 1" %} Do something here only if the variable is set to "item 1" {% case "item 2" %} item 2 things {% default %} This is default if the variable doesn't match {% endswitch %}defaulttag, that the function still runs as intendedforloop