{WRAP_SHOW_CONTENT:XX, YY : my_class}

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
User avatar
flip-flop
Moderator
Posts: 8178
Joined: Sat 21. May 2005, 21:25
Location: HAMM (Germany)
Contact:

{WRAP_SHOW_CONTENT:XX, YY : my_class}

Post by flip-flop »

A little snippet for wrapping the {SHOW_CONTENT:....} tag.

If the selected CP/CPs is/are unfilled, there is no output of wrapping DIVs.

E.g.: {WRAP_SHOW_CONTENT:CP, 19:my_class}
or without a class {WRAP_SHOW_CONTENT:CP, 19} -> fallback to the default class WRAP_SHOW_CONTENT

File name: /template/inc_script/frontend_render/rt_wrap_show_content.php

Code: Select all

<?php
// ==================================================================
// {WRAP_SHOW_CONTENT:...:class}. The same like {SHOW_CONTENT: ...
// but with a enclosed div container
// If there is/are a unfilled or unvisible CP/CPs no output is generated
// (and no div wrapper)
//
// E.g.: {WRAP_SHOW_CONTENT:CP, 19: my_class}
//    or {WRAP_SHOW_CONTENT:CP, 19}  -> fallback to the default class
//
// Default class: WRAP_SHOW_CONTENT
//
// file name: /template/inc_script/frontend_render/rt_wrap_show_content.php
// forum: http://forum.phpwcms.org/viewtopic.php?p=110898#p110898
//
// (c) 07.11.08 Knut Heermann (flip-flop) http://planmatrix.de
//      08.11.08 Updated for a better handling
// ==================================================================
// ------------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {
   die("You Cannot Access This Script Directly, Have a Nice Day."); }
// ------------------------------------------------------------------

if( strpos($content['all'], '{WRAP_SHOW_CONTENT:') !== FALSE ) {


	function func_wrap_show_content($my_param) {
	
		$my_param = str_replace(' ','',$my_param); // kill all spaces
		
		// explode parameter for SHOW_CONTENT and the optional class name
		// $my_arr[0] = SHOW_CONTENT parameter
		// $my_arr[1] = optional own class name
		$my_arr = explode(":",$my_param); 
		
		if (!empty($my_arr[1])) { $my_class = $my_arr[1]; } 	// custom class name = yes
		else {$my_class = 'WRAP_SHOW_CONTENT'; }				// custom class name = no -> default name

		// set the wrapper code
		$div_before = '<div class="'.$my_class.'"'.LF;
		$div_behind = LF.'</div>';
		
		$string = '';
		$string = showSelectedContent($my_arr[0]); 	// same as SHOW_CONTENT
		
		// Set the wrapper around 
		if (!$string == '') { $my_replace  = $div_before.$string.$div_behind; }	
		else { $my_replace = ''; }
		
	return $my_replace;
}

// And do it ======
$content["all"] = preg_replace('/{WRAP_SHOW_CONTENT:(.*?)}/e', 'func_wrap_show_content("$1")', $content["all"]);

}
?>
[UPDATE 08.11.08] More flexible input without error - like
- {WRAP_SHOW_CONTENT:CP, 19}
- {WRAP_SHOW_CONTENT:CP, 19:}
- {WRAP_SHOW_CONTENT:CP, 19:my_class}
[/UPDATE]

[UPDATE 08.11.08 No.2] For avoiding collisions:
- function name changed from func_replace to func_wrap_show_content
[/UPDATE]

Knut
Last edited by flip-flop on Sat 8. Nov 2008, 11:02, edited 3 times in total.
>> HowTo | DOCU | FAQ | TEMPLATES/DOCS << ( SITE )
photojo
Posts: 717
Joined: Wed 15. Nov 2006, 20:02
Location: Regensburg, Germany
Contact:

Re: {WRAP_SHOW_CONTENT:XX, YY : my_class}

Post by photojo »

wow, danke Knut,

hast du das mal auf die schnelle programmiert?
Kann man auf diese Weise eigene RTs erstellen?

DANKE Jo
User avatar
flip-flop
Moderator
Posts: 8178
Joined: Sat 21. May 2005, 21:25
Location: HAMM (Germany)
Contact:

Re: {WRAP_SHOW_CONTENT:XX, YY : my_class}

Post by flip-flop »

YES :D
>> HowTo | DOCU | FAQ | TEMPLATES/DOCS << ( SITE )
Post Reply