Need help with IF statement

6 posts by 3 authors in: Forums > CMS Builder
Last Post: December 12, 2011   (RSS)

Re: [sublmnl] Need help with IF statement

Makes great sense.

Here's an approach that might help.

I used it in my foreach loop to display a Facebook image as a link, only if the client entered a Facebook URL in the "facebook" field of the record.

The preg_match part of the code makes sure that an http:// is added to the URL if necessary:

<?php if ($record['facebook']): ?>
<?php if (!preg_match("/^http:\/\//", $record['facebook'])) {$record['facebook'] = "http://" . $record['facebook']; }
?>

<a class="alphabet" href="<?php echo $record['facebook'] ?>" target="_blank"> <img src="images/Facebook_icon.gif" alt="Facebook Logo" vspace="5" width="32" height="32" /></a>
<?php endif ?>


NOTE: You might want to implement the free removeExtraWhitespace plugin that Dave Edis created http://www.interactivetools.com/forum/gforum.cgi?post=84270;search_string=removeExtraWhitespace;#84270
to insure that an errant blank space doesn't trick the if statement into showing the image.

There's a lot more about working with if statements in my CMSB Cookbook www.thecmsbcookbook.com

Hope that get's you started.

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Need help with IF statement

Works Jerry. Thanks and I have your online book. I should refer to it more often.

Below is my code that I have with that works:

<?php foreach ($featuredRecords as $record): ?>
.....
....
....
...

<?php if ($record['event_venue_facebook_link']): ?><?php if (!preg_match("/^http:\/\//", $record['event_venue_facebook_link'])) {$record['event_venue_facebook_link'] = "http://" . $record['event_venue_facebook_link']; }
?><a href="<?php echo $record['event_venue_facebook_link'] ?>" target="_blank"><img src="/images/facebook_small22.png" /></a><?php endif ?><?php if ($record['event_venue_twitter_link']): ?><?php if (!preg_match("/^http:\/\//", $record['event_venue_twitter_link'])) {$record['event_venue_twitter_link'] = "http://" . $record['event_venue_twitter_link']; } ?><a href="<?php echo $record['event_venue_twitter_link'] ?>" target="_blank"><img src="/images/twitter_small22.png" /></a><?php endif ?>

<?php endforeach ?>

Re: [sublmnl] Need help with IF statement

Glad you got it going.

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Need help with IF statement

By sublmnl - December 11, 2011 - edited: December 11, 2011

Reaching out for a little more help on this one but with a twist this time.
I love the 'If Link' thing we did earlier.... but what I want to do this now:

IF (checkbox) is Yes
Then show _link

I'm talking about the '_link' that is created from the list page to a detail page.
In my list record editor, I have a field that is a checkbox <?php echo $record['has_a_page'] ?>
I only want to show the "_link" to the detail page if the checkbox is checked. I was going to wrap the <?php echo $record['title'] ?> with the IF ELSE statement because if the checkbox is not checked I still want to show the unlinked <?php echo $record['title'] ?> but I got stumped on this one.
Help?!

Re: [sublmnl] Need help with IF statement

By Jason - December 12, 2011

Hi,

Try this:

<?php if ($record['has_a_page']):?>
<a href = "<?php echo $record['_link'];?>"><?php echo $record['title'];?></a>
<?php else:?>
<?php echo $record['title']; ?>
<?php endif ?>


Does this seem to be what you're looking for?

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/