What Are Viewers?
You display content from CMS Builder on your website with viewers. Viewers are regular HTML pages containing PHP tags that load data from the CMS Builder database. With some basic HTML knowledge they can be customized to match any page design.
Creating a new viewer
Section titled “Creating a new viewer”The fastest way to create a viewer is to have CMS Builder generate one for you:
- Go to CMS Setup > Code Generator
- Select the generator for the viewer type you want
- Choose the section you want to create a viewer for
- Configure the display options
- Click Show Code
- Copy the generated code into new PHP files as instructed
- Adjust the HTML markup to match your site design
Viewer types
Section titled “Viewer types”List Pages
Section titled “List Pages”List Pages display multiple records from a section: news articles, job postings, upcoming events, and so on.
Detail Pages
Section titled “Detail Pages”Detail Pages display a single record from a section, such as the detail page for one news article or event.
Other viewer types
Section titled “Other viewer types”The Code Generator can also produce a Combo Page (a list and detail viewer combined in a single file), an RSS Feed viewer, and a Category Menu viewer that outputs nested menu HTML from category sections. These all follow the same patterns as List and Detail Pages.
Displaying fields
Section titled “Displaying fields”The standard PHP tag for displaying a field value looks like this:
<?php echo $record['fieldname'] ?>Replace fieldname with the name of your field. The $record variable is
created by the generated viewer code. Depending on your section name it may
be called something like $newsRecord or $jobRecord. The generated code
includes tags for every field in your section, so usually you only need to
rearrange them and remove the ones you don’t want.
The generated code applies htmlencode() where appropriate (around plain
text fields, for example) and leaves WYSIWYG fields unencoded so their HTML
renders. Values returned by getRecords() are not automatically HTML-encoded,
so when writing your own tags, encode user-entered content yourself with
htmlencode().