What if clauses

4 posts by 2 authors in: Forums > CMS Builder
Last Post: September 9, 2008   (RSS)

Hi

In a recent site you helped me with you put in a 'what if' clause. This enabled the page to put in a link to a gallery only when pictures are added to the page on the back end I need to do a similar thing with the present site I'm doing. In other words some shows will have pictures and some won't and I need the >>gallery link to only become active if they upload pictures.

Could you tell me what code I need to add to achieve this please? Many thanks.

Re: [chassa2556] What if clauses

By Dave - September 8, 2008

Hi Charles,

First you need to determine the name of your uploads variable. Usually it will look something like this: $newsRecord['uploads'] Use your own fieldname in the example code below.

Next, you can use some code like this to test for uploads:

<?php if ($newsRecord['uploads']): ?>
... this html or php will be shown if there are uploads ...
<?php endif ?>

Just wrap those tags around the content you want to show. Make sure the content can be removed without breaking the page design. For example if you put that around half a table and there was no uploads it would only show the bottom html for the table.

Typically you'd put it around a entire table, tr, td, or block of code.

Along the same lines, you can add a ! for "not" to test if there are "not" uploads. Like this:

<?php if (!$newsRecord['uploads']): ?>
Sorry, there are no uploads.
<?php endif ?>

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] What if clauses

what I'm after is for it to just show a link to a gallery page if there are pictures and not show the link if there are no pics.

The gallery would show in a fresh page. How would I set that up?