Solved

Template tag outputs JSON, how to format as HTML??

  • 25 March 2022
  • 3 replies
  • 216 views

Badge +2

Hello,

Our template tag {{ item.ItemOptions }} is showing as:

{'Color': 'Assorted', 'Color_Choices': 'Green, Red, Blue, Yellow, Pink', 'Text_Field': 'Text Field', 'Text_Area': 'Text Area', 'File_Upload': 'Features Needed.txt ', 'Select_Dropdown': 'Select Dropdown 1', 'Select_Radio': 'Select Radio 1', 'Select_Checkbox': 'Select Checkbox 1, Select Checkbox 2, Select Checkbox 3', 'Multiple_Select': 'Multiple Select 1, Multiple Select 2, Multiple Select 3'}

How can I format the output as HTML like:

Color: Assorted
Color_choices: Green, Red, Blue, Yellow, Pink
Text_Field: Text Field
etc.....

Thanks for any help!

 

icon

Best answer by stevekem 26 March 2022, 07:18

View original

3 replies

Badge +2

So apparently it is outputting an OBJECT not JSON, my apologies I’m new 😁

 

I tried:

{% for obj in item.ItemOptions %}
    <p>{{ obj }}</p>
{% endfor %}

 

But it’s only showing:

Color
Color_choices
Text_Field

 

And not:

Color: Assorted
Color_choices: Green, Red, Blue, Yellow, Pink
Text_Field: Text Field

Badge +2

Finally figured it out. In case anyone else might find this useful, I used:

{% for k, v in item.ItemOptions.items %}
  {{ k }}: {{ v }}
{% endfor %}

Userlevel 7
Badge +60

Hi @stevekem

 

Thank you so much for sharing your your solution with the Community! I know it will definitely help someone else in the future who is also experiencing this issue!

 

Thanks for participating in our Community and helping others!

-Taylor 

Reply