Forum

Thread tagged as: Question

Perch if / else - Not having to save region

Is there a way I can make a slideshow show a default image if the user does not add an image themselves but not have to save an empty region to activate the Perch:if statement?

Currently I have the following but this means the user still needs to save the region to define the content.

<perch:if exists="bannerimage">
      <li style="background-image: url(<perch:content type="image" id="bannerimage" label="Banner image" width="1200" help="Image must be at least 1200px width" />)"><perch:else /><li style="background-image: url(/img/default-header.jpg)"></perch:if>
James Tedder

James Tedder 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

How about using a <perch:noresults> region in the template?

Didn't work unfortunately

Drew McLellan

Drew McLellan 2638 points
Perch Support

What happened?

Nothing still says <!-- undefined content --> in the HTML

Drew McLellan

Drew McLellan 2638 points
Perch Support

You should only get that HTML comment for a new content region that does have a template picked. Is that the case in your circumstance? That you want a placeholder before the region is even defined?

I think in that circumstance it may be better to define the region using perch_content_create()

The region has been defined as it uses the Master template which is referring to my 'about' page to define its regions. However the region still needs to be saved first to make the template if statements work.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so does that suggested solution not work?

It didn't seem to make any difference. I still had Undefined content.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok. I'm not sure I have a solution for you.