1

I have strange issue and cannot find out the solution for that. I have this field (matrix with some text values): https://imgur.com/a/KaFXubJ

Also I have this entry: https://imgur.com/a/cPMrGul

And this is how it rendered (it shows not value of fields but id of matrix block table): https://imgur.com/a/SR3HgQZ

Here is how it looks like in template: https://pastebin.com/viVbPLqj

I've tried multiple combinations but nothing was solution. Also other fields are works well (fields which not related to "companyInformation" matrix).

So what may I do wrong?

  • When you dump reviewFeatured.relatedCaseStudy.first.companyInformation.companyName what is the result ? – Maxime Lafrenière Jan 28 '19 at 18:25
  • @MaximeLafrenière it's here (marked by red cycle): imgur.com/a/SR3HgQZ It's an ID of companyInformation in 'matrixblocks' table – Clark Jan 28 '19 at 18:38
1

Technically the data you're seeking are under the first matrix block (not the first data of your .companyName - which is not valid)

{% set relatedCaseStudy = reviewFeatured.relatedCaseStudy.first %}
{% set firstCompany = relatedCaseStudy.companyInformation.first %}
{{ firstCompany.companyName }}

Note: If you plan to have only one company, think about a SuperTable field in 'static' mode (only one occurence).

| improve this answer | |
  • And how to find out what field types I need to fetch via "first", and which not? I've installed "inspector" plugin but it ain't helps. Twig's dump function also not good (absolutely exactly). – Clark Jan 30 '19 at 10:15
  • 1
    .first is in fact a function that return the "first" element of an array/object. Every 'simple' fields (text, dropdown, etc.) aren't concern by this method. You can read the whole documentation fields that on Craft' website. There's a example for each field. (docs.craftcms.com/v2/fields.html#field-types) – Maxime Lafrenière Jan 30 '19 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.