4

I have a template which loops through Matrix Blocks. The site itself correctly ignores any Blocks which are 'disabled', but on viewing the page in the Live Preview, those Blocks are visible. A key part of the reason for using Craft as the CMS for this site was the draw of the Live Preview, so this is important for us to get right.

I can't see anything as part of a Matrix Block Model which would indicate an assigned status to each Block which I could access. If there was, as there is with a straight entry, I could at least do some sort of a work around e.g. forcing the collation of Blocks to only those with a particular status of 'enabled'.

This feels like it might just be a bug; I am seeing other complications with this particular Live Preview, for instance if any offset or limit is given to the Blocks, rearranging the blocks in the Live Preview has no effect either.

If anyone could shed some light / offer some advice that would be much appreciated!

5

It's definitely a bug in live preview but looks like you can work around it.

This doesn't appear documented at all—so be careful—but you can use .status() to get the block's status. It looks like an IF block is enough to get a matrix block to refresh the live preview.

{%for block in entry.matrixBlock %}
   {% if ( block.type == 'supertable' and block.status == 'enabled') %}
  {#do whatever #}
   {%endif %}
{%endfor %}

I found out about .status out awhile back messing around trying to figure out if there was a good way to display a "sold out" status for a particular show date (for example):

{%for thedate in entry.showDates.type('date').status() %}

    {% if thedate.status() == 'disabled' %}
        <strike>{{thedate.showDate|date('m/d/y')}}</strike> SOLD OUT! 
    {% else %}
        {{thedate.showDate|date('m/d/y')}}
    {%endif%}<br>

{%endfor%}
| improve this answer | |
1

According to Pixel & Tonic Support it is a known issue, submit the problem to PT Support to let them know it is a problem.

| improve this answer | |
  • Ah ok thanks, where did you find it as a known issue please? And what is the best place to submit the problem? support.pixelandtonic.com? Thanks! – Mike Vaux Feb 18 '15 at 8:52
  • I submitted a support request from the Craft Dashboard regarding this issue mid December and got this reply: Thanks for sending that in. It's a known issue, but a bit of a complicated one, unfortunately, so we haven't found a way to fix it yet. I guess both the Craft Dashboard and support.pixelandtonic.com submits tickets to the same system, so either would be fine. – Alf Vestre Feb 18 '15 at 12:51

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.