Forum

Thread tagged as: Question, Problem, Error

PHP warning when using 'different' and blocks

I've recently updated my blog post template to use blocks instead of normal perch tags. I compare the month of each post with the previous month and, if different, output the month onto the page. However, since updating the template to use blocks I get the following warning on the latest post:

Warning: array_key_exists() expects parameter 2 to be array, null given in [path]/perch/core/lib/PerchTemplate.class.php on line 956

This is the old template:

<perch:if different="postDateTime" format="F">
  <perch:if id="perch_item_index" match="neq" value="1">
    <h2><perch:blog id="postDateTime" format="F Y" /></h2>
  </perch:if>
</perch:if>

<article class="media paper paper--margin paper--folded">
  <perch:if exists="image">
    <img src="<perch:blog id="image" type="image" label="Image" bucket="images" />" class="media__img--rev media__img--padded" alt="<perch:blog id="postTitle" />" />
  </perch:if>
  <perch:if not-exists="fbpost">
    <time datetime="<perch:blog id="postDateTime" format="Y-m-d" />" class="cal-widget">
      <span class="cal-widget__t"><perch:blog id="postDateTime" format="j" /></span>
      <span class="cal-widget__d"><perch:blog id="postDateTime" format="M" /></span>
    </time>
    <h3><perch:blog id="postTitle" type="text" /></h3>
  </perch:if>
  <perch:blog id="postDescHTML" encode="false" />
  <perch:if exists="fbpost">
    <div class="fb-post" data-href="<perch:blog id="fbpost" type="text" label="Facebook Post URL" html="false" />" data-width="auto"></div>
  </perch:if>
</article>

And this is the new:

<perch:if different="postDateTime" format="F">
  <perch:if id="perch_item_index" match="neq" value="1">
    <h2><perch:blog id="postDateTime" format="F Y" /></h2>
  </perch:if>
</perch:if>

<article class="media paper paper--margin paper--folded">
  <time datetime="<perch:blog id="postDateTime" format="Y-m-d" />" class="cal-widget">
    <span class="cal-widget__t"><perch:blog id="postDateTime" format="j" /></span>
    <span class="cal-widget__d"><perch:blog id="postDateTime" format="M" /></span>
  </time>
  <h3><perch:blog id="postTitle" type="text" /></h3>
  <perch:if exists="postDescHTML">
    <perch:blog id="postDescHTML" encode="false" />
  </perch:if>
  <perch:blocks>
    <perch:block type="lead" label="Lead">
      <perch:template path="content/blocks/blog/lead.html" />
    </perch:block>
    <perch:block type="text" label="Text">
      <perch:template path="content/blocks/blog/textarea.html" />
    </perch:block>
    <perch:block type="video" label="Video">
      <perch:template path="content/blocks/blog/video.html" />
    </perch:block>
    <perch:block type="image" label="Image">
      <perch:template path="content/blocks/blog/image.html" />
    </perch:block>
    <perch:block type="facebook" label="Facebook">
      <perch:template path="content/blocks/blog/facebook.html" />
    </perch:block>
  </perch:blocks>
</article>

I've checked to see if the dates are being set correctly with 'showall' and every post has a postDateTime, so I'm not sure what could be causing the problem. Any help would be appreciated

Alan Longstaff

Alan Longstaff 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

That certainly looks like a bug. The blocks are trouncing the variable scope for the outer item loop.

I don't have an immediate solution for that, but I can look into it.

No problem, it's not an urgent issue (I can suppress it for now). Thanks for the quick reply :)

Drew McLellan

Drew McLellan 2638 points
Perch Support

Now to figure out how on earth to fix it!

Haha, rather you than me!