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 depending on the template which was used. One way to do it would be the deployment of a newsbox.


Let's say there are two templates: “SummerTemplate” and “WinterTemplate”.
While using the “SummerTemplate” you want to show images which resemble summer themes and text which refers to the images. During winter time you want to use the “WinterTemplate” with different images and different text.

Possible Solution:

In the “default” template.htm file you usually say:

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

In the template dependant case, however, you say now instead:

<?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: 2018/04/05 14:49 (external edit)
Webdesign: NMuD chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0