This is the community forum. For a developer response use the Client Area.
Follow us on Facebook, Twitter and YouTube!

Different layouts on different web pages
#1

I have some pages where I'd like to have very simple comments: just name, e-mail, town, country and comment. But on other pages I may want to have something more complex, so I figured out a way to modify the comments and form layout on any page on your site. I'm using Commentics version 2.1, so references to line numbers may be different in other versions. And I have only tested this in 2.1, so I don't know how well it will work in other versions, but the basic approach should work.

In /comments/includes/commentics.php, between lines 106 and 107, insert the following code:
//get page main file name in the form "name.ext" and construct a name in the form "name_cmtx_ovr.ext"
$pInfo = pathinfo($_SERVER["SCRIPT_NAME"]);
$fName = $pInfo['filename'] . "_cmtx_ovr" . "." . $pInfo['extension'];
if (file_exists($fName)) {
require_once $fName; //load overload file if it exists
}

If the basic page file name is "foobar.php", this code looks for a file named "foobar_cmtx_ovr.php", and if it exists, loads it into the php execution stream. This code is inserted at the point where all of the settings have been loaded, and the global php variables that control the layout have been set based upon your Admin Panel settings. Immediately following this the templates are loaded, and those variables control the layout. And this is the point where you can override those variables before the page is displayed. For example, if "foobar_cmtx_ovr.php" contains:

<?php
$cmtx_settings->enabled_bb_code = false;
?>

the BB Code will be disabled on foobar.php. This manually overrides the setting in the Admin Panel, but it only does it for that one page.
Keep in mind that:

1. You can override any number of settings by merely including more lines in the "_cmtx_ovr" file. You can troll the comments.php and form.php templates to find other $cmtx_settings->xxxx global variables.

2. You can have a different "_cmtx_ovr" file for every page on your site.

3. Note that this can also be used to turn on features that are off in the Admin Panel. Remember, this just overrides the settings for a single page.

4. This is an override. If you turn off a feature on a particular page, going back to the Admin Panel will not let you turn it back on. You'll have to go into the "_cmtx_ovr" file and set the value of the global variable accordingly, or remove it altogether.

5. If you want to return to the basic Admin Panel settings, merely delete or rename the "_cmtx_ovr" file. If it doesn't exist with the right name in the same directory as the page, the page will display based on the Admin Panel settings.

Also, there might be a couple of gotchas that I haven't uncovered yet, so you'll have to experiment.

I think the easiest way to handle this is to use the Admin Panel to set up a layout that you'll use on most of your pages, then use a local override file to change one or two pages. It's not as elegant as doing the whole thing through the Admin Panel, but it works.

Enjoy!
Reply


Possibly Related Threads…
Thread / Author Replies Views Last Post

Forum Jump:


Users browsing this thread: 1 Guest(s)