Template dependent Content

Once, there was a question how to make content dependent on layout/template usage. The person wanted to change templates and provide one page or several pages with with different content dependent on the template which was used. One way to do it would be the deployment of a newsbox.

Problem:

Let’s say there are two templates: “SummerTemplate” and “WinterTemplate”.
While using the “SummerTemplate” he wants to show images which resemble summer themes and text which refer to the images. During winter he wants to use the “WinterTemplate” with different images and different text.

Possible Solution:

In the “default” template.htm file it says:

<?php echo editmenu();?>
<?php echo content();?>
<?php echo submenu();?>

Instead of that it is said now:

<?php echo editmenu();?>
<?php if ($news=="") {echo content();}else{echo newsbox($news);echo content();} ?>
<?php echo submenu();?>

If a page contains a script containing the variable “$news”, a newsbox will be generated above the content area. (You have to uses CSS to style it.) If no such a script is present on a page, there wont be a newsbox either, just the content area.

In order to load template specific content, first hidden pages have to be generated (#CMSimple hide#). Let’s have two of them: one called “Summer”, the other called “Winter”. The pages are filled with season dependent content.

Next, there is the “Home” or “Start” page which is supposed to have a season dependent look. We add to the content the CMSimple script:

#CMSimple if ($cf['site']['template']=="SummerTemplate") {$news="Summer";} else {$news="Winter";} #

Now, while using “Summertemplate” the newsbox will be filled by the content of the hidden page called “Summer”. Template switch to the “WinterTemplate” will call up the content of the hidden “Winter” page.

Alternative method:

Instead of a newsbox the CMSimple function geturl() could be used. In that case no changes would be made to the template.htm file. You just use the CMSimple script:

#CMSimple if ($cf['site']['template']=="SummerTemplate") {$output.=geturl('http://myWebSite/index.php?Summer&print');} else {$output.=geturl('http://myWebSite/index.php?Winter&print');} #
tips_and_tricks/newsbox/template_dependent_content.txt · Last modified: 2007/12/12 20:55 by till