1

I need to get the content of a field in the Matrix of the English localization in my template. I already have the handle of that field for the current language, but I don't know how to get the English version for that field...

I found this for getting a field of a Matrix:

{% set fields = craft.sections.getSectionByHandle('news').getEntryTypes()[0].getFieldLayout().getFields() %}

But that works of course again only for the field in the current localization... which I already have.

2

You should be able to set the desired locale by adding .locale('en') to your code.

Like so:

{% set fields = craft.sections.getSectionByHandle('news').getEntryTypes()[0].locale('en').getFieldLayout().getFields() %}

Assuming you've got english defined as en.

| improve this answer | |
1

thanks Michael, that brings me further. This already works:

{{craft.entries.id(entry.id).locale('en').first().myMatrix[blockCount].myFieldinsideMatrix }}

But I dont know what to fill in for "blockCount". That leads me to a more general question: A field inside an entry of a local is always linked to the same field in another local. But the fields inside Matrixes seem not, because I can create completely different blocks for each local.

That meens what I am trying to do is not possible, right?

| improve this answer | |
  • 1
    What do you need? The same layout of blocks between locales but with translated content? Or a different set of blocks for each locale? In the first case, you have to mark the individual blocks as translatable but not the matrix field (I think), for the second case, you're better off not making the individual ones translatable – mrsmn Aug 2 '17 at 11:20
  • You are right, thats it. Now I am really afraid that all my content (even of the first language) gets lost if I uncheck "translateable" for the matrix... – Jan Aug 2 '17 at 12:29
  • Take a backup and see what happens? I honestly have no idea ^^ – mrsmn Aug 2 '17 at 12:32
  • ok, this is what I found out: After changing the matrix to not translateable, nothing changes until you edit the content in one of the locals. After doing this, craft copies all the content from that local to all the others. From that point on you can start to translate the fields inside the matrix... this is a relieve :) – Jan Aug 2 '17 at 12:58
  • @Jan Just to correct here, Craft doesn't copy "all the content from that locale to all the others" - it only does it for locales where the matrix is empty (which is a relief, otherwise pre-existing translations would be wiped out). – James Smith Jan 5 '18 at 12:38
1

Here we go, the final answer:

{% set blockHeadingEnglish = craft.entries.id(entry.id).locale('en').first().myMatrix.id(block.id).first().myFiel %}
| improve this answer | |

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.