Hi Themeco Team,
I am partially referencing back to my older support request but with a more specific example this time.
Let’s say we have an ACF custom taxonomy Month with all 12 months added as the taxonomy terms. What we need is on page load to grab the current date and to define the current month. Then with respective TWIG Template we compare if it is true or false for each ‘Month’ taxonomy term. That should allow us to pre-populate ‘true’ or ‘false’ value inside Selected option while in Breakout Mode inside CS Forms Checklist Option. In the end, we need just the current month taxonomy term to be pre-selected on page load and maybe also on Clear Filter button flush. But even though the TWIG script works in a text element correctly, it doesn’t work in the ‘Selected’ option in the form. It doesn’t matter if the output is ‘true’ or ‘false’; that item is always chosen as it is in the ‘true’ state when the TWIG template is linked. I do not understand why.
Here instead of
false we link respective TWIG template.
And here is the TWIG template script for January only:
{% set month = global.date|date('m') %}
{% if month == 01 %}
true
{% else %}
false
{% endif %}
Ideally we need another TWIG script that will check each taxonomy term in the Loop dynamically and put true or false for its each Selected option, no matter what month it is. Probably {{ term.slug }} should be involved somehow to make it possible. I am not sure how to properly debug such a code when the TWIG Template is linked already to the Selected option.
I don’t think it’s a good idea to add each month’s option in the form by hand. Then, create a separate TWIG script for each month and link them together. I prefer to show only those terms which are used in the looper output dynamically. Although the current month may not be included in the current loooper output. Script then needs to pick the next month until we get some output. That sounds rather complex, so probably it is not possible without cusom coding or maybe it is the default behaviour if we use radio option. I just put this idea as the most simple starting point for discussion of a possible solution.
Please let me know if I am thinking in the wrong direction. Maybe there is a simpler way to accomplish it. Or maybe it is currently not possible with what CS and CS Forms have in their toolset.



