Forum
perch:if and perch:else
I have a section that uses a bootstrap button. If the background color is red I want the blue button to show, if the background section is black I want a red button to show. I have tried several combinations of the perch:if and perch:else tags and I can't get it to show the correct color button. My template code is below. If anyone can help, I would greatly appreciate it.
<section class="<perch:content label="Background color for Section" id="sectionClass" type="select" options="dark gray bg|content dark, solid black bg|content black, solid red bg|content red" />_section">
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="white_rule">
<div class="row">
<div class="col-sm-4">
<img src="perch/resources/hands-phone.png" class="img-responsive pull-left">
</div>
<div class="col-sm-8">
<h1>Transportation Insurance Quote</h1>
<p class="lead">Getting a quote has never been easier ...<br />
Convenient online form lets you request an insurance quote <br />in just a few simple steps.</p>
<perch:if exists="sectionClass" match="contains" value="red_section">
<a href="#" class="btn btn-primary">REQUEST A QUOTE NOW</a>
<perch:else />
<a href="#" class="btn btn-danger">REQUEST A QUOTE NOW</a>
</perch:if>
<h2>or Call Today 800.926.1212</h2>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
I've also tried the following and nothing shows. up.
<perch:if id="sectionClass" match="contains" value="red_section">
<a href="#" class="btn btn-primary">REQUEST A QUOTE NOW</a>
</perch:if>
<perch:if id="sectionClass" match="contains" value="black_section">
<a href="#" class="btn btn-danger">REQUEST A QUOTE NOW</a>
</perch:if>
Based on your template, the possible values for
sectionClass
are:but you're testing for strings like
red_section
. So that's never going to match because that's not one of the values it could be.Try this:
You're right! i missed that. The _section is being added after the dropdown list selection. Thank you. I appreciate your help.
Actually, that didn't work. But changing the exists="sectionClass" to id="sectionClass" works and now I have the expected response. Thank you.
Sorry, the
exists
is wrong. I copied that from your example and forgot to fix it. My fault.