Copy link to clipboard
Copied
Hi all,
I am trying to lay out a Web App with approx 300 fields containing product specifications.
Each of these fields also needs a label associated with it - something like this:
<ul>
<li>Input Voltage: {{voltage}}</li>
<li>Retransmission Current: {{current}}</li>
<li>Excitation Voltage: {{excitation}}</li>
... onwards to 300 fields!
</ul>
Obviously the above will work, but I was wondering whether there is a way to take my 300 fields and add them to a JSON array so that I can loop through them - something like the below?
[
{ "label": "Input Voltage", "value": "{{voltage}}" },
{ "label": "Retransmission Current", "value": "{{current}}"},
{ "label": "Excitation Voltage", "value": "{{excitation}}"}
]
I would be so grateful if someone could point me to an example of how to do this, if it's possible. I have hunted through BC knowledgebase and forums for several hours and found a lot of info on how to manipulate an existing array, but not how to create one...
Really appreciate any help you can give, and apologies if this has been answered elsewhere - I really did try to help myself before posting! ![]()
Creating arrays of objects isn't practical in Liquid. Instead, I'd create two arrays of Strings, maybe something like this:
{% assign keys = "voltage|excitation|current" | split: "|" -%}
{% assign labels = "Input Voltage|Retransmission Current|Excitation Voltage" | split: "|" -%}
<ul>
{% for key in keys -%}
<li>{{ labels[forloop.index0] }}: {{ webappitems[key] }}</li>
{% endfor -%}
</ul>
The webappitems part will have to change, depending on context.
Copy link to clipboard
Copied
Creating arrays of objects isn't practical in Liquid. Instead, I'd create two arrays of Strings, maybe something like this:
{% assign keys = "voltage|excitation|current" | split: "|" -%}
{% assign labels = "Input Voltage|Retransmission Current|Excitation Voltage" | split: "|" -%}
<ul>
{% for key in keys -%}
<li>{{ labels[forloop.index0] }}: {{ webappitems[key] }}</li>
{% endfor -%}
</ul>
The webappitems part will have to change, depending on context.
Copy link to clipboard
Copied
That is exactly the kind of solution I was hoping for and works perfectly with my Web App - thank you SO much, Robert! ![]()
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more