What if clauses

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

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

By chassa2556 - September 9, 2008

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?

Re: [chassa2556] What if clauses

By Dave - September 9, 2008

Do you have the gallery page setup already? You'd want to create that first. Then get the link working to open in a new page. Then wrap it in the if tags above so it only shows when there actually are images.

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