Changing Project Files

From phpCMS

Jump to: navigation, search

Question: How can I change the layout by exchanging the project file?

Answer: by Samson (08.02.2006)

Contents

[edit] Introduction

If you want to offer users the choice of another layout, you may ask yourself how to implement this with phpCMS. Your first consideration may be passing the alternative template via URI:

index.htm?template=/template/alternativ.tpl

For a persistent layout experience, this parameter would have to be appended to all links of this site - a quite inacceptable solution.

The second solution is changing the layout via a CSS file. You would have to write a Plugin which exchanges the CSS-link in your template and sets the Cookies accordingly.

Both variants have been heavily discussed in the phpCMS forums, but there's still a third alternative: Exchanging the project file! Unfortunately, this alternative is not supported by phpCMS. Even changing the global project file setting in the configuration file does not work.

I will now present a solution which makes it possible to access the project file. You will have to write a small patch for phpCMS and a tiny Plugin.


[edit] class.parser_page_phpcms.php

function CheckProject, line 55, after

if (isset($this->content->PROJECT)) {
  $temp = trim($this->content->PROJECT[0]);
} else {
  $temp = false;
}

insert

if($DEFAULTS->INI_SWITCH == 'on') {
  if($DEFAULTS->INI_FILES[$_COOKIE["phpcmsinifile"]]) {
    $temp = $DEFAULTS->INI_FILES[$_COOKIE["phpcmsinifile"]];
  }
}  

[edit] default.php

Insert additional configuration values:

$this->INI_SWITCH = 'on';
$this->INI_FILES = array("Standard 3clm"=>"/template/home.ini",
                         "Demo4you"=>"/template/demo_4you_home.ini");

The array INI_FILES holds the descriptions of the layouts and paths of the project files.

[edit] iniswitch.php

This is a plugin to display links for changing the layout. It also sets a cookie and issues a reload of the current page:

<?php
  
  if($_GET["layout"]) { 
    // set new layout, set cookie for 1 year and issue page reload
    setcookie ("phpcmsinifile",$_GET["layout"],time()+31536000,"/");
    Header("Location:".$CHECK_PAGE->path."/".$CHECK_PAGE->name);
  }

  // build navigation
  $count = 0;
  while(list($key,$value) = each($DEFAULTS->INI_FILES)) {
    $count++;
    $Ausgabe .= '<a href="?layout='.$key.'" title="'.$key.'">'.$count.'</a> '; 
  }         
	$current = count($Tags);
	$Tags[$current][0] = '<!-- PLUGIN:INISWITCH -->';
	$Tags[$current][1] = 'INI-Switcher: '.$Ausgabe;

?>

[edit] Template

Now you have to include this plugin in the template file for every layout, e.g.:

{PLUGIN FILE="$plugindir/iniswitch.php" TYPE="DYNAMIC"}


To output a link for switching the layout, you use

<!-- PLUGIN:INISWITCH -->

[edit] Functionality

In the first step, the parser replaces the project file given in the content file with a new one, as long as INI_SWITCH is on and the Cookie set. If the project file is not found, the global project file will be used.

The plugin reads the array holding the INI files from the configuration file and shows the links for switching the layout. When a visitor clicks a link, the plugin sets the Cookie and reloads the page.

[edit] Pros and Cons

This only works if all content files use the same project file. If your site already has multiple content files for a single layout, you may find exchanging the CSS file the easier solution.

[edit] Extensibility

Links could be generated without using a plugin, if the layout-switching links are generated by the parser.

Main Page: Tutorials MainPage | Top Page: MiniHowTos MainPage

Diese Seite in anderen Sprachen: Deutsch

Personal tools