interactivetools.com
Quickstart Guide...
How to Install
How to Upgrade
How to Move Servers
How to Private Label
Restore Hacked Sites
Admin Menu
General Settings
Private Labeling
User Accounts
Section Editor (List)
Add New Editor
Section Editor (Edit)
Field Editor
Text Field
Text Box
Wysiwyg
Date/Time
List
Checkbox
Upload
Separator
Regional Settings
Code Generator
Show Code
Viewers
Viewer Options
Displaying Uploads
Search Engines
Advanced Topics
In-Depth Getting Started Guide
Working With Generated Code Guide
Special Fieldnames
Changing and Removing File Extensions
Demo Mode

View Changelog »
Glossary
Need Help? Questions?
Post in forum »

Working With Generated Code Guide

You've got CMS Builder installed and you have your Section Editors set up. Now you're ready to start adding the generated code from CMS Builder onto your designed pages. This guide will go over what each piece of CMS Builder code does, and some tips for working with it.
The "STEP 1" Code

<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block to the TOP of your page BEFORE anything else. */
  require_once "/path/to/lib/viewer_functions.php";

  list($my_sectionRecords, $my_sectionMetaData) = getRecords(array(
    'tableName'   => 'my_section',
    'limit'       => '5',
  ));

?>
This code is used by CMS Builder at the very beginning of your page to determine which section it should be displaying records from. Options that determine how records are displayed are set here as well. This code would only be changed to add custom features - for most uses it doesn't need to be changed at all.
The "foreach" Code

This piece of code signifies the start point of the code that's going to be repeated for each record on a List Viewer page:
<?php foreach ($my_sectionRecords as $record): ?>
This line of code is used to determine the end point of the code that will be repeated for each record on a List Viewer page:
<?php endforeach; ?>
You won't want to change this code at all, but it's useful to look at it as the 'wrapper' within which code gets repeated to display each record on List Viewer pages. Note that the "foreach" code is also used on Detail Viewer and List Viewer pages to display your file uploads, which you can see in the STEP 2a code block.
The "echo" Code

<?php echo $record['num'] ?>
This type of code is the one you'll be working with the most in CMS Builder. It's there to pull in text content entered through CMS Builder onto your web page. In the example above, the code will display the current record's number on the web page. Likewise, this line of code will display the current record's title:
<?php echo $record['title'] ?>
If you're looking to control how text is displayed on your site, those code pieces are the ones you'll want to wrap your <div> or <font> tags around.
The "echo date" Code

<?php echo date("D, M jS, Y g:i:s a", strtotime($record['time'])) ?>
This code piece is used to display dates and times on your pages. You can change the format the date is displayed in by following the instructions here.
The "echo join" Code

<?php echo join(', ', getListLabels('my_section', 'cities', $record['cities'])); ?>;
This code piece is very similar to the "echo" code, but it's only used for multi value list fields. What's happening here is that CMS Builder is displaying each value selected for this field, separated by a comma. If a few cities were selected for this field, they would be displayed on the page like this:
Vancouver, New York, Sydney, Oslo
To separate them by a dash instead, change the code like this:
<?php echo join(' - ', getListLabels('my_section', 'cities', $record['cities'])); ?>
Now this is how they would be displayed:
Vancouver - New York - Sydney - Oslo

The STEP 2a and "if" Code

This is the code used to display file and image uploads. It checks for a certain condition, and if it's met it will run the code that follows it. The code first checks to see if an image has a thumbnail, and if so uses the code for displaying thumbnail images:
          <?php if ($upload['hasThumbnail']): ?>
            <img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>
If the image doesn't have a thumbnail, the code moves on to check the next condition, which is whether the uploaded file is an image or not. If it is an image, then it is displayed at its full size:
          <?php elseif ($upload['isImage']): ?>
            <img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>
Finally, if the uploaded file is not an image then the code for displaying a file attachment link is used:
          <?php else: ?>
            <a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/>

          <?php endif ?>
By customizing the code following each stage of the "if" statement, you can determine how images and file attachments are displayed on your pages. You can also customize the "No records were found!" text used here to change the message displayed when no records are present in the section:
    <?php if (!$my_sectionRecords): ?>
      No records were found!<br/><br/>
    <?php endif ?>
Copyright © 1999-2024 interactivetools.com, inc.