Is there a way to use If Then simply?

10 posts by 4 authors in: Forums > CMS Builder
Last Post: October 14, 2009   (RSS)

By Moonworks - August 6, 2009

Is there a simple way to use soemthing like If Then statements?

For example, I want to show only sections that have been filled in.

The best example would be that if somebody was asked for their first, middle and last name and there was a section on the created page like this:

First:
Middle:
Last:

If they did not fill in a section for middle name, that line wouldn't show up, so the result would just show:

First:
Last:

I have various sections to be filled in, but not all of them will be used. I don't want to have a blank space where they would show up if filled in.
High quality residential training for writers, actors & Film Making - Click Here for further information

Re: [Moonworks] Is there a way to use If Then simply?

By Chris - August 6, 2009 - edited: August 6, 2009

Hi Moonworks,

There certainly is! In your viewer code, wrap the HTML you want to make optional with the following PHP code:

<?php if ($record['middle']): ?>
Middle: <?php echo $record['middle'] ?><br/>
<?php endif ?>


Voila!

Please let us know if you have any more questions!
All the best,
Chris

Re: [chris] Is there a way to use If Then simply?

By Moonworks - August 8, 2009

Thanks, that was painless [:)]
High quality residential training for writers, actors &amp; Film Making - Click Here for further information

Re: [Moonworks] Is there a way to use If Then simply?

By benedict - October 7, 2009

Hi Chris,

I have a follow up to this one:

I have a hospitality short course website.
The courses are entered in a section called "hospitality".
Course dates are entered in a "Short Course Calendar" section which pulls the courses from the "hospitality" section via a dropdown

This is all working fine. My problem is this:

I have a situation where the "course dates" section for a course should only show if there have been course dates entered in the "Short Course Calendar" section. So I have done this:

<?php if ($short_course_calendarRecords): ?>
<?php echo date("D j M Y", strtotime($record['course_date'])) ?>
<?php endif ?>


This works fine - but now I need to add a constraint that if the "course_type" in the "hospitality" section is either "Short Courses For Kids" or "Short Course For Adults", instead of not showing any dates, just to say "Please contact us for the next available course".

I guess I have never put 'where' criteria in the body of a page, only in the head so that's why I'm stumped.

Thanks for any help you can offer.

Re: [benedict] Is there a way to use If Then simply?

By Chris - October 8, 2009

Hi benedict,

Would this do the trick?

<?php if ($short_course_calendarRecords): ?>
<?php echo date("D j M Y", strtotime($record['course_date'])) ?>
<?php elseif ($record['course_type'] == "Short Courses For Kids" || $record['course_type'] == "Short Course For Adults"): ?>
Please contact us for the next available course
<?php endif ?>


Hope this helps!
All the best,
Chris

Re: [benedict] Is there a way to use If Then simply?

By Damon - October 10, 2009

Hmm...the code Chris provided should work. We will need to take a closer look at the admin and the actual published page.

Can you send in a support request with:
- your CMS Builder login details,
- URL for the published page
- and link to this forum post wih the page code attached
https://www.interactivetools.com/support/email_support.cgi
Cheers,
Damon Edis - interactivetools.com

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

Re: [Damon] Is there a way to use If Then simply?

By Chris - October 11, 2009

Hi benedict,

Courses or Course? Is this problem simply a typo? :)

either "Short Courses For Kids" or "Short Course For Adults"


elseif ($record['course_type'] == "Short Courses For Kids" || $record['course_type'] == "Short Course For Adults"):


Nothing appears using this command for a Short Courses For Adults course.

All the best,
Chris

Re: [chris] Is there a way to use If Then simply?

Yes, you were right. Thanks guys.

Re: [benedict] Is there a way to use If Then simply?

By Chris - October 14, 2009

Hi benedict,

Good to hear you got this sorted out! :)
All the best,
Chris