Demo:
http://www.sottwell.com
To keep a page’s template from being switched, place
in its assigned template. You can still use that template for switching other pages to, just pages originally assigned that template won’t be switched.
On your page switching menu, have links passing the template ID in the query string:
<a href="[~[*id*]~]&template=1">Original template</a>
<a href="[~[*id*]~]&template=2">2-column template</a>
<a href="[~[*id*]~]&template=3">1-column template</a>
And here’s the plugin code:
if(!strstr($modx->documentContent, "donotswitch")) {
if (isset($_GET['template'])) {
$overrideTemplate=$_GET['template'];}
else if (isset($_COOKIE['template'])) {
$overrideTemplate=$_COOKIE['template'];
}
if (isset($overrideTemplate) && is_numeric($overrideTemplate)) {
$modx->documentObject['template']=$overrideTemplate;
$sql = "SELECT * FROM ".$this->getFullTableName("site_templates")." WHERE ".$modx->getFullTableName("site_templates").".id = '".$overrideTemplate."';";
$result = $modx->dbQuery($sql);
$rowCount = $this->recordCount($result);
if($rowCount>1) {
$this->messageQuit("Incorrect number of templates returned from database", $sql);
} elseif($rowCount==1) {
$row = $this->fetchRow($result);
$modx->documentContent = $row['content'];
}
setcookie("template",$overrideTemplate,time()+604800, "/", "", 0);
}
}
Set its System Events to be Template Service Events, OnLoadWebDocument.
A cookie is set so the user’s selection is maintained across switchable pages in the site. If a user doesn’t have cookies enabled, he’ll get the one page switched, but the rest will not change. No harm done, it won’t have any ill effects on the default template.