3

I have an entries in a section called 'garden', with a matrix field called 'sowing' - this matrix has a block called 'locationDate' and two fields 'sowingDate' and 'sowingLocation'.

I want to loop through and show the last 5 things sown in the garden, so based on other examples and using low blocks, I have this code:

{% set allSown = craft.lowblocks.blocks.fieldId(12).type("locationDate").order("sowingDate").limit(5) %}
{% set entryIds = [] %}

{% for sown in allSown %}
    {% set entry = sown.title %}
    {% set entryIds = entryIds | merge([entry.id]) %}
{% endfor %}

{% set entries = craft.entries.section("garden").id(entryIds).fixedOrder(true).status("live,pending") %}

{% for sown in entries %}
    {{ sown.title }}<br />
{% endfor %}

So my question is, why can't I view the entries, and what do I need to do to display the date of the matrix field? It seems like it should working, but I am missing something for sure.

** note I need to have a matix date there as there are often multiple sowing locations and dates per entry.

2

I have not worked with Lowblocks yet, but it looks like it returns an array of Matrix block models. To get to the related entries you need to access the owner property.

{% set entryIds = [] %}
{% for sown in allSown %}
    {% set blockId = sown.id %}
    {% set entryIds = entryIds|merge([blockId.owner.id]) %}
{% endfor %}

But do you really need those entry IDs? You could just display the blocks?

{% for sown in allSown %}
    {{ sown.owner.title }}
    {{ sown.sowingLocation }}
    {{ sown.sowingDate }}
{% endfor %}
| improve this answer | |
  • hmm tried that but I am getting this: Object of class Craft\ElementCriteriaModel could not be converted to string /home/aaronjay/craft/templates/index.html(-1) – Aaron Mar 31 '15 at 7:26
  • What gives you this error? The line you print owner.title? – carlcs Mar 31 '15 at 7:30
  • nah the date - {{ sown.sowingDate|date("d - M") }} this resolved it when I take the {{ sown.sowingLocation }} out. – Aaron Mar 31 '15 at 7:35

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.