Multiple Viewers On Same Page (need help)

5 posts by 2 authors in: Forums > CMS Builder
Last Post: March 6, 2008   (RSS)

By rasbro - March 5, 2008

There have been a couple of posts related to this but I am not seeing any good examples, plus I have tried a few things on my own with some frustration.

I want to add a viewer for a leftnav section I created. This will allow me to edit the leftnav content from within CMS Builder instead of editing the template. In order for this work I will need to add this leftnav section viewer to my existing page templates. Some of my pages are product listings (List Viewer) and others are product pages (Page Viewer). Which viewer do I use for adding the leftnav viewer to my existing pages?

Here is what I tried so far:

--- Trial #1 (added to existing page using List Viewer) ---

Placed at beginning of document...

<?php
require_once "/path/.../lib/viewer_functions.php";
$options = array(); // NOTE: see online documentation for more details on these options
$options['tableName'] = 'insert_leftnav'; // (REQUIRED)
list($listRows, $listDetails) = getListRows($options);
?>

Placed in leftnav area of document...

<?php foreach ($listRows as $record): ?>
<?php echo $record['leftnav_content'] ?>
<?php endforeach ?>

This resulted in errors.


--- Trial #2 (added to existing page using List Viewer) ---

Placed at beginning of document...

<?php
require_once "/path/.../lib/viewer_functions.php";
$options = array(); // NOTE: see online documentation for more details on these options
$options['tableName'] = 'insert_leftnav'; // (REQUIRED) MySQL tablename to list record from. Example: "article";
$options['recordNum'] = ''; // (optional) Record number to display. Example: "1"; Defaults to number on end of url, then 1
$options['where'] = ''; // (ADVANCED) MySQL WHERE conditions to use INSTEAD of recordNum to look up record. Example: "fieldname = 'value'"
$record = getRecord($options);
?>

Placed in leftnav area of document...

<?php if ($record): ?>
<?php echo $record['leftnav_content'] ?>
<?php endif ?>

This displays the content and seems to work fine.

Incidently, when doing the same thing in Trial #1 and #2 with an existing page using a Page Viewer, I get errors with Trial #1 and for Trial #2 I see the leftnav content but get errors for all other content.

I hope I have given enough info to help you understand the issue when I try to use multiple viewers.

Thanks,
Brian

Re: [rasbro] Multiple Viewers On Same Page (need help)

By Dave - March 5, 2008

It depends what kind of content you have. If you have a single record you want to display (such as from a single-page section) then method #2 would we the way. If you had a list of pages or records you wanted displayed then you'd want to use method #1.

Assuming you're using method #2, one thing you can do to avoid collisions is to rename some of the variables. For example, instead of using $record, you could rename those to $left_nav or something else.

If you're still getting errors, see if you can post an url to a test page with the errors and attach the viewer to your post and I can have a look at it for you.

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

Re: [Dave] Multiple Viewers On Same Page (need help)

By rasbro - March 6, 2008

Okay, so would I rename all references to $record parameter, like this:

In the viewer at the beginning of the document...

from, $record = getRecord($options);
to, $leftnav = getRecord($options);

And also in the body of the document...

from, <?php echo $record['leftnav_content'] ?>
to, <?php echo $leftnav['leftnav_content'] ?>

Is this true for the List Viewer parameters also?:

from, list($listRows, $listDetails) = getListRows($options);
to, list($anynameiwantRows, $anynameiwantDetails) = getListRows($options);

and...

from, <?php foreach ($listRows as $record): ?>
to, <?php foreach ($anynameiwantRows as $record): ?>

If this is the case then it certainly opens a lot of options for me. I had no idea these parameters such as $record or $listRows could be changed. Any other parameters or viewer attributes that can be changed like this? Sorry for all the questions - I'm getting excited at the possibilities!

Thanks,
Brian

Re: [rasbro] Multiple Viewers On Same Page (need help)

By Dave - March 6, 2008

Yes, that right. Those are just PHP variables so you can give them any name you want. Basically anything that starts with a dollar sign (like $this) you can try renaming.

Give a try and feel free to ask as many questions as you like. :)
Dave Edis - Senior Developer
interactivetools.com