NAVIGATION
This is an old revision of the document!
This RT is to show how with can the help of tags in the page structure, the output of the pages can be influenced.
Assumed problem:
In each of the four seasons is a special CSS files are loaded. In addition to the template, depending on the terminated season e.g., another image is being loaded.
Procedure:
In the site structure in the field “category infotext” by “HOME” (ie ID = 0) is entered a tag which controls the behavior of the RT in /frontend_render/ , e.g.
[JAHRESZEITEN] #Tag1, #Tag2, Tag3,.#Tag4,...[/JAHRESZEITEN]
The wrapper [JAHRESZEITEN] separates the tags from the remaining entries in this field.
Not valid tags are simply disabled by using a leading #. (In the above example the tag Tag3 is active).
<note>
Attention, with the next update please ensure that the file config/phpwcms/conf.indexpage.inc.php is previously backed up and after the update compared with the new one. (This is the special case HOME)
Incidentally, the file can be edited via FTP to change the tags
</note>
In the RT, the appropriate tags are also entered, such as (in active state so without adding #)
$my_tags = 'fruehling, sommer, herbst, winter';
On these tags registered here the field “category infotext” is examined. The field is investigated for this entered tags. At the first match, this matched tag is used and processed. There is only one valid tag.
CSS:
A new CSS file is loaded, depending on the day. In order not to change the load sequence of the CSS files, a dummy or a fallback CSS file is created in template/inc_css/* and in the correct place in the template involved.
This CSS file is exactly replaced by the RT at this point. The RT is marked with the name of the CSS file to be swapped:
$my_css = 'master_template.css';
Attention: note Upper/lower case!
The name of the exchanged CSS file is equal to the name of the tag, e.g.
Tag = sommer → CSS-Datei = specific/sommer.css (The replacement CSS files are located in the directory template/inc_css/specific/)
The result is visible here:
No active tag:
The tag “Winter” is active:
Meta-text for “description” if “Home” is active (ID=0 alias=index)
Natürlich ist es auch möglich bestimmten Content auszutauschen.
Im unteren Bereich des Skriptes V1.1 sind einige Beispiel aufgezeigt (Custom Funktionen).
Bsp01.: direktes ersetzen im Template/Content
Bsp02.: Ersetzen mit Umschlieszer (wrapper) im Template/Content
In der Vorlage/Content steht z.B.: “Jetzt [SEASON]im Jahr ist es farbig[/SEASON].”
Bsp03.: Ersetzen mit Tag {TAG} im Template/Content
In der Vorlage/Content steht z.B.: “Jetzt ist der {SEASON} da.”
Sicherheitshalber muss nun noch geprüft werden, ob noch Umschließer-Reste im Content vorhanden sind (Das passiert z.B. wenn kein TAG trifft).
Dazu kommt noch die Voreinstellung (Fallback) bei einem Einzelersetzer wie z.B. {ERSETZE}. Trifft kein Tag aus unserer Liste, muss hier ein Default-Wert eingetragen werden.
rt_tag_in_site_structure V1.0 26.11.09
Docu: –
Forum: http://forum.phpwcms.org/viewtopic.php?p=121111
Autor: K.Heermann (flip-flop) http://planmatrix.de
CMS Version: >= 1.3
Version: V1.0
Tag: –
Filename: rt_tag_in_site_structure.php
Folder: template/inc_script/frontend_render/
Condition: → /config/phpwcms/conf.inc.php
<?php /** * 26.11.09 KH (flip-flop) tags in site structure "category infotext" * This RT is to show how with can the help of tags in the page structure, the output of the pages can be influenced. * * Usage: sample Replacement Tag * * in the field "category infotext" in site structure (in this example we uses * the category HOME) * * Tag: * -> [JAHRESZEITEN]#Fruehling, #Sommer, #Herbst, Winter[/JAHRESZEITEN] * (We trigger on "Winter", there is no # in front) * * Meta descrition if you want: * -> My descrition text for home * * Corresponding tags/entries in this rt: * -> $my_tags = 'FRUEHLING, SOMMER, HERBST, WINTER'; * * encloser: * -> $enclose = 'JAHRESZEITEN'; * * dummy/fallback css filename: * -> $my_css = 'master_template.css'; * **/ // ---------------------------------------------------------------- // OBLIGATE CHECK FOR PHPWCMS CONSTANTS if (!defined('PHPWCMS_ROOT')) {die("You Cannot Access This Script Directly, Have a Nice Day.");} // ---------------------------------------------------------------- // ist im Feld Beschreibung der Seitenebene" etwas vorhanden? if (!empty($content["struct"][0]['acat_info'])) { // ===== Usereingabe ===================================== // Vorgabe: Tags eintragen, wie im Infofeld $enclose = 'JAHRESZEITEN'; // Umschlieszer $my_tags = 'fruehling, sommer, herbst, winter'; // Die Tags $my_css = 'master_template.css'; // Name der Dummy-CSS Datei bzw. // Fallback Datei die ersetzt wird // ===== ENDE Usereingabe ================================ // Tags abholen aus "HOME" ID=0 $info = returntagcontent($content["struct"][0]['acat_info'], $enclose); // irgendeine Tagansammlung vorhanden? if ( !empty($info['tag']) ) { $be_tags = explode(',',$info['tag']); // BE-Tags holen $my_tags = strtolower($my_tags); // normieren $tag = ''; // Hier wird der Tag festgehalten // Vergleich ob ein Tag aus dem BE in der Vorgabe enthalten ist foreach ($be_tags as $key => $value) { $be_tags[$key] = strtolower(trim($value)); // normieren if (strpos($my_tags, $be_tags[$key]) != false) { // Tag gefunden $tag = $be_tags[$key]; break; // foreach Abbruch da gefunden } } // Custom Funktionen, wie CSS austauschen oder Teile im Template ersetzen // ============================================================= if ( !empty($tag) ) { // wenn Tag vorhanden, dann z.B. Dummy/Fallback-css austauschen // die Position in der Reihenfolge der Dateien bleibt eralten // ------------------------------------------------------- $key = array_search($my_css, $block['css']); if ($key) $block['css'][$key] = 'specific/'.$tag.'.css'; // Ersetzer im Template // ------------------------------------------------------- if ($tag == 'winter') // wenn "winter" dann mache folgendes: { $content['all'] = str_replace('{RANDOM:templates/header-random/normal}', '{RANDOM:templates/free_XL/header-random/weihnachten}', $content['all']); } } // Das ganze getagge löschen, wenn "Beschreibung der Seitenebene" fuer die description gebraucht // ============================================================================================== $content["struct"][0]['acat_info'] = replace_cnt_template($content["struct"][0]['acat_info'], $enclose, ''); $content["struct"][0]['acat_info'] = trim($content["struct"][0]['acat_info']); } } ?>
V1.1: Exemplary extended by several Replacer for the content (See section “Custom Functions”).
<?php /** * 26.11.09 KH (flip-flop) tags in site structure "category infotext" * This RT is to show how with can the help of tags in the page structure, the output of the pages can be influenced. * V1.1 * * Usage: sample Replacement Tag * * in the field "category infotext" in site structure (in this example we uses * the category HOME) * * Tag: * -> [JAHRESZEITEN]#Fruehling, #Sommer, #Herbst, Winter[/JAHRESZEITEN] * (We trigger on "Winter", there is no # in front) * * Meta descrition if you want: * -> My descrition text for home * * Corresponding tags/entries in this rt: * -> $my_tags = 'FRUEHLING, SOMMER, HERBST, WINTER'; * * encloser: * -> $enclose = 'JAHRESZEITEN'; * * dummy/fallback css filename: * -> $my_css = 'master_template.css'; * **/ // ---------------------------------------------------------------- // OBLIGATE CHECK FOR PHPWCMS CONSTANTS if (!defined('PHPWCMS_ROOT')) {die("You Cannot Access This Script Directly, Have a Nice Day.");} // ---------------------------------------------------------------- // ist im Feld Beschreibung der Seitenebene" etwas vorhanden? if (!empty($content["struct"][0]['acat_info'])) { // ===== Usereingabe ===================================== // Vorgabe: Tags eintragen, wie im Infofeld $enclose = 'JAHRESZEITEN'; // Umschlieszer $my_tags = 'fruehling, sommer, herbst, winter'; // Die Tags $my_css = 'master_template.css'; // Name der Dummy-CSS Datei bzw. // Fallback Datei die ersetzt wird // ===== ENDE Usereingabe ================================ // Tags abholen aus "HOME" ID=0 $info = returntagcontent($content["struct"][0]['acat_info'], $enclose); // irgendeine Tagansammlung vorhanden? if ( !empty($info['tag']) ) { $be_tags = explode(',',$info['tag']); // BE-Tags holen $my_tags = strtolower($my_tags); // normieren $tag = ''; // Hier wird der Tag festgehalten // Vergleich ob ein Tag aus dem BE in der Vorgabe enthalten ist foreach ($be_tags as $key => $value) { $be_tags[$key] = strtolower(trim($value)); // normieren if (strpos($my_tags, $be_tags[$key]) != false) { // Tag gefunden $tag = $be_tags[$key]; break; // foreach Abbruch da gefunden } } // ==================================================================== // Custom Funktionen, wie CSS austauschen oder // Teile im Template/Content ersetzen // ==================================================================== // TAG ueberhaupt vorhanden und TAG in unserer Menge enthalten? if ( (!empty($tag)) AND (strpos($my_tags, $tag) != false) ) { // wenn Tag vorhanden, dann z.B. Dummy/Fallback-css austauschen // die Position in der Reihenfolge der Dateien bleibt eralten // ------------------------------------------------------- $key = array_search($my_css, $block['css']); if ($key) $block['css'][$key] = 'specific/'.$tag.'.css'; // ------------------------------------------------------- // ------------------------------------------------------- // Bsp01.: direktes ersetzen im Template/Content // ------------------------------------------------------- if ($tag == 'winter') // wenn "winter" dann mache folgendes: { $content['all'] = str_replace('{RANDOM:templates/header-random/normal}', '{RANDOM:templates/free_XL/header-random/weihnachten}', $content['all']); } // ------------------------------------------------------- // Bsp02.: Ersetzen mit Umschlieszer (wrapper) im Template/Content // In der Vorlage/Content z.B.: // "Jetzt [SEASON]im Jahr ist es farbig[/SEASON]." // ------------------------------------------------------- switch($tag) { // Verwendet wird die Funktion: // replace_cnt_template($text='', $tag='', $value=''); case 'winter': $content['all'] = replace_cnt_template($content['all'], SEASON, 'im Winter ist es weiß'); break; case 'fruehling': $content['all'] = replace_cnt_template($content['all'], SEASON, 'im Frühling ist es grün'); break; case 'sommer': $content['all'] = replace_cnt_template($content['all'], SEASON, 'im Sommer ist es gelb'); break; case 'herbst': $content['all'] = replace_cnt_template($content['all'], SEASON, 'im Herbst ist es braun'); break; } // ------------------------------------------------------- // Bsp03.: Ersetzen mit Tag {TAG} im Template/Content // In der Vorlage/Content z.B.: // "Jetzt ist der {SEASON} da." // ------------------------------------------------------- switch($tag) { case 'winter': $content['all'] = str_replace('{SEASON}', 'Winter', $content['all']); case 'fruehling': $content['all'] = str_replace('{SEASON}', 'Frühling', $content['all']); case 'sommer': $content['all'] = str_replace('{SEASON}', 'Sommer', $content['all']); case 'herbst': $content['all'] = str_replace('{SEASON}', 'Herbst', $content['all']); } // ------------------------------------------------------- } // ---ENDE if ( !empty($tag) ) ------------------------- // All unsere [wrapper] und {Tags} in der Vorlage/Content loeschen, // wenn noch vorhanden (wenn kein Tag gesetzt wurde) // und Fallback setzt bei {TAG} // -------------------------------------------------------------------- $content['all'] = str_replace('{SEASON}', 'Regen', $content['all']); // Fallback $content['all'] = preg_replace('/\[SEASON\](.*?)\[\/SEASON\]/is', '$1', $content['all']); // -------------------------------------------------------------------- // Loeschen des ganze "Getagges" in der Struktuebene, // wenn "Beschreibung der Seitenebene" fuer die description gebraucht wird // --------------------------------------------------------------------- $content["struct"][0]['acat_info'] = replace_cnt_template($content["struct"][0]['acat_info'], $enclose, ''); $content["struct"][0]['acat_info'] = trim($content["struct"][0]['acat_info']); // --------------------------------------------------------------------- } // ---ENDE if ( !empty($info['tag']) ) ------------------------- } // ---ENDE if (!empty($content["struct"][0]['acat_info'])) ---- ?>