magnus
21. September 2023 um 14:00
1
I have created an new config field in theme.json. It’s a boolean field called „productsku“ with default value of „false“.
Is it possible to check this value (false or true) within a twig template? I want to use that in a if-statement to show/hide a twig block.
Have tried just to print it with „config.fields.productsku“ and „theme_config.productsku“. But none seems to work.
Maybe not possible…?
theme_config(„var“)
Change the „ to the Cort ones, can’t type it on my device.
magnus
24. September 2023 um 13:36
3
Thanks Max - and sorry for a late reply.
I tried this (inside a block of an extended template), but nothing is printed.
theme_config("productsku")
The config field have a default value of „false“.
I must be missing something other, important.
With that function you only get the value. If you want to print it use {{ … }} around the function. Honestly I don’t know what will happen if you print a bool value. Maybe false converts to null and then you won’t see anything.
magnus
25. September 2023 um 04:33
5
Yes, I’m already using the {{ … }}
Maybe it is so that a false boolean dont print anything…
Try it with {{ false }} and {{ true }} in your template and then you know for sure.
Use the twig manual, maybe you can cast Boolean to string or write your own twig function.
magnus
25. September 2023 um 14:35
7
Great!
I went straight in tried with an if-statement - and it works perfect
{% if theme_config("productsku") %}
// some code to show the product SKU
{% endif %}