builder-7000
builder-7000

Reputation: 7627

Jekyll - Evaluate a string before assignment

I need to capture a string into a variable tag, then use this variable in site.tags.tag. The code is:

{% capture tag %}programming{% endcapture %}
{{ tag }}
{%- assign titles = site.tags.tag | map: "title" -%}
{{ titles }}

This code only prints prints:

programming

But if I replace site.tags.tag with either site.tags.programming or site.tags.'programming' I get the desired output:

programming
title1 title2

Is there a way to evaluate the variable tag before the assignment? After reading a similar question I tried site.tags.{{tag}} but it didn't work.

Upvotes: 1

Views: 180

Answers (1)

David Jacquel
David Jacquel

Reputation: 52829

site.tags[tag] might be what you're looking for.

Upvotes: 1

Related Questions