Access json data using a variable name as lookup value #1797
Answered
by
pdehaan
alexanderameye
asked this question in
Q&A
-
<ul class="note-tags">
{%- for tag in tags | filterTagList -%}
{%- set color = tagcolors.Math -%}
<li>
<a style="background-color: {{color}};" href="/tags/{{tag}}">{{tag}}</a>
</li>
{%- endfor -%}
</ul> I have a json data file like this that is supposed to allow me to give each tag a color.
Now I'm trying to do this where I access the right color from the json data based on the tag but this syntax is not right and I get an error "expected name as lookup value, got {" <ul class="note-tags">
{%- for tag in tags | filterTagList -%}
{%- set color = tagcolors.{{tag}}} -%}
<li>
<a style="background-color: {{color}};" href="/tags/{{tag}}">{{tag}}</a>
</li>
{%- endfor -%}
</ul> Is there a suggested workaround for this? I would love to be able to define the colors for a tag in one spot. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Answered by
pdehaan
May 27, 2021
Replies: 1 comment 1 reply
-
I think you want: {%- set color = tagcolors[tag] -%} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
alexanderameye
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you want: