3

After doing some experimentation in looping through MatrixBlockModel, it seems that even though each block has a dateUpdated property, this value is never unique to each block, but is shared between all blocks in the Entry.

{% set timeLimit = now | date_modify("-2 min") %}
{% for block in entry.blocks %}
  {% if block.dateUpdated >= timeLimit %}

    {{ block.dateUpdated | date(dtFilter) }}

  {% endif %}
{% endfor %}

If the entry has 6 blocks, and I update one of those blocks and save, the same date will output 6 times for about 2 minutes, then nothing will output.

Can anybody confirm this?

3

Yes I can confirm, currently the dateUpdated property returns the same datetime object for every block model. It's actually the save date of the entry (entry.dateUpdated) that is saved to the craft_matrixblocks table in the DB.

Can't say if it's intended to work like this though.

  • Thanks for confirming @carlcs. If this is the intended behavior, its a bit of a bummer because I have a use case (checking for recently-updated matrix blocks via a javascript JSON request) that is far more difficult, maybe even impossible, without a unique updated date time for each block. It's also inconsistent, because each block does have a unique date_created property. – cmal Aug 23 '14 at 19:36
  • @cmal the (shared) property is probably only saved to make this work: block.dateUpdated. But actually that wouldn't be necessary because you could also do: block.owner.dateUpdated. – carlcs Aug 28 '14 at 7:19
  • I did a feature request for this on g+. – carlcs Aug 28 '14 at 7:19

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.