Template Wahl
Template Wahl
Wie kann man den User mehrere Templates zur Wahl stellen? Normalerweise kann man doch nur 1 Template pro Seite einstellen.
Re: Template Wahl
das es hier etwas gutes gibt ist mir nicht bekannt
Die letzte CMS war meine eigene, die das perfekt gelöst hat, aber die habe ich verkauft.
Die letzte CMS war meine eigene, die das perfekt gelöst hat, aber die habe ich verkauft.
Re: Template Wahl
Das ist 'ne gute Frage ...Konto wrote: Wie kann man den User mehrere Templates zur Wahl stellen? Normalerweise kann man doch nur 1 Template pro Seite einstellen.
Da die CSS in der Datenbank abgelegt ist, könnte ich mir vorstellen, dass sich da eine Datenbankabfrage zur Umschaltung des Stylesheets programmieren läßt. Da ich aber kein Coder bin, schau mal hier:
http://forum.cmsmadesimple.org/index.ph ... l#msg11351
Piratos hat da beschrieben, wie man das Template und das CSS extern "lagert". IMHO könnten auf diese Weise auch Scripte zum CSS-Switching, wie man sie von statischen Seiten kennt, wieder zum Einsatz kommen

Re: Template Wahl
Gibt es diesen Thread (
http://forum.cmsmadesimple.org/index.php/topic,2090.msg11351.html#msg11351) auf deutsch? Oder ein Tutorial.
http://forum.cmsmadesimple.org/index.php/topic,2090.msg11351.html#msg11351) auf deutsch? Oder ein Tutorial.
-
- Translator
- Posts: 169
- Joined: Sat Mar 12, 2005 12:30 pm
Re: Template Wahl
Oder schau mal hier http://forum.cmsmadesimple.org/index.ph ... l#msg11639
Da gibts ein Styleswitcher-Modul
...
Da gibts ein Styleswitcher-Modul

Re: Template Wahl
Könnte mir jemand vielleicht die Auswahl in einem Dropdownfeld machen?
Code: Select all
<?
/**
* StylesheetSwitcher is a module for CMS Made simple (cmsmadesimple.org) that presents a user switchable style selector on the front end of the site
* Written by Thomas Williams (tom@webrocketdesign.com)
* Copyright 2005 Web Rocket Design, 4 Blue Coat Buildings, Durham, UK, DH11RF
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**/
class StylesheetSwitcher extends CMSModule
{
function GetName(){ return 'StylesheetSwitcher';}
function GetVersion(){ return '0.1';}
function IsPluginModule(){ return true;}
function GetAuthor(){ return 'Thomas Williams';}
function GetAuthorEmail(){ return 'tom@webrocketdesign.com';}
function GetHelp()
{
return "
<h3>What does this module do?</h3>
<p>It provides an interface for users to switch stylesheets. The stylesheets it uses are the selection of additive stylesheets that are located under Content > stylesheets.</p>
<h3>How should I use it?</h3>
<p>There are two ways to integrate this page into the front end, both represent themselves as standard tags, so you use {cms_module module=\"stylesheetswitcher\"} with any of the arguments below.</p>
<h3>What parameters are there?</h3>
<p>There are a couple of tunable parameters:<br />
<ul>
<li><strong>use_javascript</strong> <em>[true|false]</em> Set this styleswitcher to use AJAX in compliant browsers. <strong>not implemented yet</strong></li>
<li><strong>format</strong> <em>[selector|summary|summary_link|link]</em> This can have three valid values: 'selector' will display a page content that allows a user to select a selection of page styles (ie more than one). 'summary' displays a smaller drop down that is suitable for inline display ('summary_link' displays the same drop down with a link to a copy of the output from 'selector'). 'link' provides a link to a page containing 'selector'</li>
</ul>
</p>
";
}
function GetChangeLog()
{
?>
<p>Author: Thomas Williams <a href="mailto:tom@webrocketdesign.com">tom@webrocketdesign.com</a><br />
Please send all bug requests through <a href="mailto:coding@webrocketdesign.com">coding@webrocketdesign.com</a></p>
<b>Change History:</b><br/>
<p>Version 0.1</p>
Initial Release 15/11/05
<?php
}
/**
* Returns a modified stylesheet if either a $_COOKIE or $_GET variable is detected
* $_GET variables over-ride the $_COOKIE. This allows for a preview style functionality
*/
function ContentStylesheet(&$stylesheet)
{
$style = $this->get_style();
if(strlen($style) > 0)
{
$css = $this->cms->db->Execute("SELECT css_text FROM ".cms_db_prefix()."css WHERE css_id IN (".str_replace('&',',',$style).")");
if ($css && $css->RowCount() > 0)
{
while($row = $css->FetchRow())
$stylesheet .= $row['css_text'];
}
elseif(strcmp($style,'__nocss') == 0)//Remove all css.
{
$stylesheet = '';
}
}
return $stylesheet;
}
function DoAction($action, $id, $params, $return_id = '')
{
if(strcmp($action,'switch') == 0)
{
$style = $this->get_style($id);
if(strlen($style) > 0)//No style has been passed, remove any cookie
{
setcookie('style',$style,strtotime('+10 years'));
}
else
{
setcookie('style','',time() - 3600);
}
}
$use_javascript = isset($params['use_javascript']) ? strcmp($params['use_javascript'],'true') == 0 : true;
if(isset($params['format']))
{
switch($params['format'])
{
case 'summary' : $this->draw_summary($id,$return_id,$use_javascript,false);//No link
break;
case 'summary-link': $this->draw_summary($id,$return_id,$use_javascript,true);//Show link
break;
case 'link' : echo $this->CreateLink($id, 'selector', $return_id, (isset($params['text']) ? $params['text'] : 'Select Stylesheet'));
break;
case 'selector' : $this->draw_selector($id,$return_id,$use_javascript);
break;
}
}
else//By default draw the selector
{
$this->draw_selector($id,$return_id,$use_javascript,(isset($params['nocss']) ? strcmp($params['nocss'],'true') == 0 : true));
}
}
/**NOT IN API**
* Draw a inline element that can display a list of the appropriate elements
*/
function draw_summary($id,$return_id,$use_javascript,$display_link = false)
{
$style = $this->get_style($id);
$styles = $this->cms->db->Execute("SELECT css_id, css_name FROM ".cms_db_prefix()."css");
if($styles && $styles->RowCount() > 0)
{
$options = array();
$index = -1;
while($row = $styles->FetchRow())
{
$options[$row['css_name']] = $row['css_id'];
if(strcmp($row['css_id'],$style) == 0)
{
$index = count($options) - 1;
}
}
//Extra options for special circumstances.
$options['Default style'] = '__nocss';
$index = strcmp($style,'') == 0 ? count($options) - 1 : $index;
if($index == -1 && strlen($style) > 0)
{
$options['Custom'] = $style;
$index = count($options) - 1;
}
echo $this->CreateFormStart($id,'switch',$return_id,'post','',true);
echo "<fieldset>";
echo $this->CreateInputHidden($id, 'prefix', $id, 'id="stylesheet-prefix"');
echo $this->CreateInputDropdown($id,'style',$options,$index);
echo $this->CreateInputSubmit($id,'save','Switch');
echo "<br />";
if($display_link)
{
echo $this->CreateLink($id, 'selector', $return_id, 'Advanced controls');
}
echo "</fieldset>";
echo $this->CreateFormEnd();
}
}
/**NOT IN API**
* Draw a element selection page
*/
function draw_selector($id,$return_id,$use_javascript)
{
$style = $this->get_style($id);
$style_arr = explode('&',$style);
$checked = false;
$styles = $this->cms->db->Execute("SELECT * FROM ".cms_db_prefix()."css");
if($styles && $styles->RowCount() > 0)
{
$options = array();
while($row = $styles->FetchRow())
{
$stylesheet = array('id' => $row['css_id'], 'value' => $row['css_id'],'label' => $row['css_name']);
if(strcmp($row['css_id'],$style) == 0)//An exact match
{
$stylesheet['checked'] = 'checked';
$checked = true;
}
elseif(!$checked && in_array($row['css_id'],$style_arr))
{
$stylesheet['checked'] = 'possible';
}
$style_arr = array_diff($style_arr,array($row['css_id']));
array_push($options,$stylesheet);
}
//Now stick in the no css options
$nocss = array('id' => 'nocss','label' => 'Default Style', 'value' => '__nocss');
if(strcmp('',$style) == 0)//No style is where we're at.
{
$nocss['checked'] = 'checked';
$checked = true;
$style_arr = array();
}
array_push($options,$nocss);
if($checked)//We have found an exact match, remove any possibles.
{
$remove_possibles = create_function('&$entry,$key','if(isset($entry["checked"]) && strcmp($entry["checked"],"possible") == 0) unset($entry["checked"]);');
array_walk($options,$remove_possibles);
}
if(!$checked && count($style_arr) == 0)//We have found a set that matches exactly. Switch possibles to checked.
{
$confirm_possibles = create_function('&$entry,$key','if(isset($entry["checked"]) && strcmp($entry["checked"],"possible") == 0) $entry["checked"] = "checked";');
array_walk($options,$confirm_possibles);
}
elseif(count($style_arr) > 0 AND strlen($style) > 0)//They have somehow managed to set a unique combination, add a custom option.
{
$remove_possibles = create_function('&$entry,$key','if(isset($entry["checked"]) && strcmp($entry["checked"],"possible") == 0) unset($entry["checked"]);');
array_walk($options,$remove_possibles);
array_push($options,array('id' => 'custom', 'label' => 'Custom style', 'value' => $style, 'checked' => 'checked'));
}
echo $this->CreateFormStart($id,'switch',$return_id,'post');
echo $this->CreateInputHidden($id, 'prefix', $id, 'id="stylesheet-prefix"');
foreach ($options as $row)
{
echo $this->CreateInputCheckbox($id, 'style[]', $row['value'], (isset($row['checked']) && strcmp($row['checked'],'checked') == 0 ? $row['value'] : null), 'id="stylesheet-'.$row['id'].'"');
echo '<label for="stylesheet-'.$row['id'].'">'.$row['label'].'</label>';
echo "<br />";
}
if($use_javascript)
{
echo "<span id=\"stylesheet-preview\"></span>";
}
echo $this->CreateInputSubmit($id,'save','Save Changes','id="stylesheet-submit"');
echo $this->CreateFormEnd();
}
}
/**NOT IN API**
* Get the style
*/
function get_style($prefix = '')
{
$value = null;
if(isset($_GET[$prefix.'style']))
$value = $_GET[$prefix.'style'];
elseif(isset($_POST[$prefix.'style']))
$value = $_POST[$prefix.'style'];
if(!is_null($value))
{
if(is_array($value))
$value = implode('&',$value);
if(strpos($value,'__nocss') === false)
return $value;
}
elseif(isset($_COOKIE['style']))
{
return trim($_COOKIE['style']);
}
return '';
}
}
?>
Re: Template Wahl
Für diese Dinge könnte man hervorragend mit Smarty arbeiten, einfach schnell und billig.
Re: Template Wahl
Versuch's mal so:Konto wrote: Könnte mir jemand vielleicht die Auswahl in einem Dropdownfeld machen?
Code: Select all
{cms_module module="stylesheetswitcher" format="summary"}
Re: Template Wahl
Für diese Dinge könnte man hervorragend mit Smarty arbeiten, einfach schnell und billig.
Stimmt, aber es gibt Leute, die Smarty nicht verstehen. Ich sehe es so: fuer Programmers, gibt's ein Ansammlung Methodenlehren, und fuer Endbenutzer gibt's ein andere Ansammlung.
(Wie immer, entschuldige mich ich fuer mein schlecht Deutsch.)
Stimmt, aber es gibt Leute, die Smarty nicht verstehen. Ich sehe es so: fuer Programmers, gibt's ein Ansammlung Methodenlehren, und fuer Endbenutzer gibt's ein andere Ansammlung.
(Wie immer, entschuldige mich ich fuer mein schlecht Deutsch.)
Many modules available from the http://dev.cmsmadesimple.org
The CMS Made Simple Developer Cookbook is now available from Packt Publishers!
The CMS Made Simple Developer Cookbook is now available from Packt Publishers!