Just to clarify, what's the theme settings that you'd like to loop through here? Based on our documentation, it doesn't appear that theme.items() is a supported hubl.
Are you looking to loop through items in module HTML+HubL? If so, you can check out this documentation: Module and Theme Fields Overview.
Hey @WendyGoh I think you are right. But for us, theme developers would be a nice feature to have a way to list in HUBL all theme settings. I still haven't give up on this. The is a dict so, reading the hubl docs, there is a way to do a for loop to list every sing setting.
Also, your team has an error in the docs that affected the loop. The error was already correct and since then I haven't tried.
We seem to keep running across the same challenges!
I'm trying to to exactly the same thing. Trying to output all the theme variables to modify CSS without going through each one in the JSON file.
I thought this would work, but it only includes the key for the first array.
{{ theme|tojson }}
Can't seem to find a way to loop through all the nested arrays easily. This is where I'm at and it works. However, it requires manual stepping through each level and there's alot of nesting in globals. I'm not expert with Python syntax or Jinja. However, I feel like there's got to be an easier way to grab all the theme variables.
Theme
{%for item in theme.items() %}
{{item.key|e}} : {{item.value|e}}
{% endfor %}
Spacing
{%for item in theme.spacing.items() %}
{{item.key|e}} : {{item.value|e}}
{% endfor %}
Fonts
{%for item in theme.fonts.items() %}
{{item.key|e}} : {{item.value|e}}
{% endfor %}
Global
{%for item in theme.global.items() %}
{{item.key|e}} : {{item.value|e}}
{% endfor %}
@ndwilliams3 I think we are both building the same thing hahahaha 🙂
I know that we need to build a recursive loop with maximum length validation per level and detect the type of variable to detect long/list/dict to keep going on a deeper level and than test the variable again to detect number/font/text/rich text in order to print the values.
I have done this for different platforms, I just don't have the availability. If we could get the THEME in a JSON format would be amazing, like your proposal: