Joining variables while injecting frontmatter from csv

I have a set of data in _data/company.csv I’m trying to inject

{% if page.categories == "companies" %}
  {% assign name = page.name %}
  {% assign sortedtags = site.data.companies.[name].parent | join: site.data.companies.[name].related | sort %}
{% else %}
  {% assign sortedtags = site.tags | sort %}
{% endif %}

but I got this error:

Liquid Exception: Liquid syntax error (line 6): Expected id but found open_square in "{{site.data.company.[name].parent | join: site.data.company.[name].related | sort }}" in /_layouts/tags.html

any help or suggestions would be appreciated

The problem is with site.data.companies.[name]. Correct it with site.data.companies[name] instead.

1 Like

heyyyy great and so quick. thanks!

1 Like

ok… so now I’m super confused and nothing seems to be working.

I pared down my code and find that I’m not actually getting any result by this method

I clicked resolved before because my build error went away, but actually no results, yet

I have this on a page whos data is in that particular data file, and what I’m expecting here is for it to print the row of that spreadsheet bearing the name of that page.

{% assign name = page.name %}

{{ site.data.companies[name] }}

meanwhile I did verify that {{ page.name }} actually gives the name of that page… what I can’t seem to manage is displaying any data from it.

I cleaned up my data in case of any interference from stray commas or extra double quotes that might be confusing to the interpreter…

only thing Im wondering now is if there can be some capitalization issue here. but after that I’m running out of attempts.

what I figured out is that the data file is consumed and stored as a hash. This will take some more thought, but I think I got this… just a little more loopage.

for the win:

{% assign name = page.name %}
{% for company in site.data.companys %}
  {% if company.name == name %}
    {{ company.parent }}    
    {{ company.related }}    
  {% endif %}
{% endfor %}