Forum

Thread tagged as: Question, Problem

Perch:before inside Perch:if issue

USING Perch: 2.8.15, PHP: 5.4.26,

For some reason the content between my <perch:before> and <perch:after> tags is not working when they are within a <perch:if>?

If I remove the the <perch:if> code then before/after content shows. If I add the <perch:if> code back only the code in the middle shows?

This is my template. It is called in using perch_content_custom.

<perch:if exists="featured">
<perch:before>
<div class="banner">
      <div class="row">
      <div class="col-xs-12">
        <h2 class="text-center">Featured Products</h2>
          <div class="owl-four owl-carousel">
</perch:before>
              <div id="da-thumbs" class="da-thumbs item">
              <li><a href="/shop/product.php?s=<perch:content id="slug" type="slug" />">
              <img class="img-responsive product-img" src="<perch:content type="image" id="product-image" label="Product Image" width="200" height="300" crop="true"/>" alt="<perch:content id="productTitle" label="Product Title" type="text"/>" />
              <div>
              <span>
              <p class="brand"><perch:categories id="brand" label="Product Brand" set="brand" required="true" ><perch:category id="catTitle" /></perch:categories></p>
              <h3 class="product"><perch:content id="productTitle" label="Product Title" type="text" /></h3>
              <h4 class="price">£<perch:content id="extra1" type="text" label="Buy from" required="true" /></h4>
              <button class="button orange">View Product</button>
              </span>
              </div>
              </a></li>
              <div class="text-center">
              <p class="brand"><perch:categories id="brand" label="Product Brand" set="brand" required="true" ><perch:category id="catTitle" /></perch:categories></p>
              <h3 class="product"><perch:content id="productTitle" label="Product Title" type="text" /></h3>
              <h4 class="price">£<perch:content id="extra1" type="text" label="Buy from" required="true" /></h4>
              </div>
              </div>
<perch:after>
            </div><!-- /owl-carousel -->
        </div><!-- /col12 -->
      </div><!-- /.row -->
    </div><!-- /.secondary-banner -->
</perch:after>
</perch:if>
James Tedder

James Tedder 0 points

  • 6 years ago

Problem solved. My fault.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, great.

Bugger - Not sure what's happening. It seems to be going wrong again? All the Code in-between the <perch:before> tags is being stripped out, but the <perch:after> is working?

Drew McLellan

Drew McLellan 2638 points
Perch Support

perch:before runs for the first item, and perch:after for the last.

So if the first item doesn't display due to an if then you won't get any output.

I am getting an output of all my products with 'Featured' tick on. The only thing which is not out putting is the following code:

<div class="banner">
      <div class="row">
      <div class="col-xs-12">
        <h2 class="text-center">Featured Products</h2>
          <div class="owl-four owl-carousel">
Drew McLellan

Drew McLellan 2638 points
Perch Support

Is the first item in the set featured?

It's pulling content in from my Shop page so I am not sure which item is first?

Drew McLellan

Drew McLellan 2638 points
Perch Support

So as I say, if the first item doesn't display due to an if then you won't get any output from perch:before.

If the perch:before isn't optional, don't include it in the perch:if block.

Got ya. I have now moved the <perch:if> in-between the Before and After tags and all works now.