How to access config field from theme.json?

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. :thinking:

Maybe not possible…?

theme_config(„var“)

Change the „ to the Cort ones, can’t type it on my device.

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. :laughing:

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.

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.

Great!
I went straight in tried with an if-statement - and it works perfect :smiley:

{% if theme_config("productsku") %}
 // some code to show the product SKU
{% endif %}