UNDERSTANDING THE BUILT IN CODE GENERATOR - Jun 7th, 2015
|
The code generator built in to the CMSB Interface (Adnin>Code Generator can save time and effort when creating viewers for your site, but it can be a bit confusing at first.
To help you to understand the code generator, after you’ve created your 2 section editors, click on “Code Generator” in the admin section of your CMSB interface.
You’ll see a list of options under “Create a Viewer”. The only two you should focus on are “List Page” and “Detail Page”.
List pages are used to show the records in a multi-record editor. Detail pages are used to show data from a single record editor or from a specific record in a multi record editor.
Once you’ve populated your sections with some data, you can copy the entire generated code into a blank PHP document and upload it to your server to see what that generated code looks like in a viewer.
DETAIL PAGE CODE Start by clicking on “Detail Page”. Click on the “Single record sections: Load first record in database” radio button and choose “About Us” from the pull down list. And click on “Show Code”
The first lines of code up to <!DOCTYPE html PUBLIC... are required to load CMSB and the data from your “about_us” database.
From <!DOCTYPE html PUBLIC... through <!-- STEP2: Display Record... is pretty standard HTML code
After that you’ll find the PHP code that pulls data from your database and displays that data.
For example, the line of code Title: <?php echo htmlencode($about_usRecord['title']) ?> pulls the information from the “title” field of your “abou_us” editor and displays (echos) that information after the text “Title:”. “htmlencode” is not mandatory, but it helps to insure that the code is displayed correctly.
LIST PAGE CODE Now let’s look at the code that gets generated for a list page.
Go Back to Admin>Code Generator but this time choose List Page from the “Create A Viewer” list “Events”. Then choose “Events” from the pull down menu, make sure that “Show all records” is checked, and Click on Show Code.
Notice that the LOAD RECORDS code at the top of the page is different then it was for the Detail Page. This is because you will be looping through the records in this multi-record editor and showing specific data from all “events” records on your list page viewer, together with links to show detailed information about a specific record on your detail page.
In Step2: you’ll see <?php foreach ($eventsRecords as $record): ?>. This tells the database to loop through each record in the database and pull specific information from each record.
The next lines, for example, Title: <?php echo htmlencode($record['title']) ?> pull the data from the title field of the record, and displays (echoes) that information after the text “Title:”.
STEP 2a: Display Uploads for field 'images' STEP 2a may seem a bit confusing at first because of the amount of information that it contains, but let’s take it piece by piece and it will become clearer.
The first lines through the <blockquote> is just a reminder of some of the special field names can be used inside this foreach loop to pull data from your records.
Next you’ll find a second foreach loop. <?php foreach ($record['images'] as $index => $upload): ?> This one says loop through each upload in the field “images” (in the record that the first foreach loop is looking at) so that some information about that upload can be displayed.
This is where it gets a bit confusing...
Next, there’s Upload Url: <?php echo $upload['urlPath'] ?>, which is the code that you’d use to display (echo) the URL of the upload.
Then there’s a line of commented code <!-- Uploads: Copy the tags from below that you want to use, and erase the ones you don't need.
You’ll need to remove that line if you want to display the entire generated code as a viewer.
The next lines of code are the ones that you will use in your viewer to display different types of uploads.
Since you have uploaded images and have generated thumbnails for those images, you would use the line: <img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /> as your image tag.
Since foreach loops have to be instructed to end, you would need to use one <?php endforeach ?> tag to end the $upload loop and another <?php endforeach ?> to end the $record loop in your viewer code.
DETAIL PAGE FOR A MULTI-RECORD EDITOR This time, when you go to Admin>Code Generator, choose Detail Page, then choose “Events” from the pull down list, check Multi record sections: Get record # from end of url, and click on “Show Code”.
Again the LOAD RECORDS Code is slightly different from the others and in STEP 2 and 2A the code specifies the name of the section in the PHP code, as it did for Single Record viewers.
|
The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact
Interactive Tools for information on the downloading of the software or the purchasing of licenses.