View source for Template Boxes

{{toc numerate=1}}

===Multi-line actions and formatters===
The main goal is that the user can move each argument on a own line for better readability.
  * info boxes
  * content templates 

#|
*| methods | syntax | dynamic | parsed | processing | folder |*
|| Action | ##""{{name param... }}""## | yes | each non cached request | PostWacko | action/ ||
|| Formatter | ##""%%(type  param... ) content%%""## | no  | once | WackoFormatter | formatter/ ||
|#
These are the two favorite ways to expand the markup rules. Among other things, the use of these methods does not require a detailed analysis of the initial class of the Wacko formatter.

So you can write your own actions or a dedicated formatter which parses your predefined syntax.
  1. ##""{{tpl_name param... }}""##
  2. ##""%%(tpl  param... ) content%%""##

Thus, whether you chose a action or a formatter, depends on the necessity to have methods for combining static and dynamic data, such as database queries, or not.

  * ((/Doc/English/Markup WackoWiki Markup))


<[To make this approach expandable to whatever you like we just should treat wiki-pages as data objects.
Then one can use {{include}} as I have mentioned before or any other kind of a new tool to work with such objects.
We have already page_lang ##VARCHAR(5)## in pages table - to set language, and formatting ##VARCHAR(20)## that can be used to say that some pages are not ordinary wiki-pages but "data objects".
This requires some changes to catalog, revisions, history tracking tools etc. -- ((user:Elar9000 Elar9000))]>

===How to write your own content templates.===
Very simple example without advanced array usage, functions, styles or filters.

====Action====
This action has no dynamic data, it serves here only as a example in comparison to the formatter below. Usually you don't want use a action for only static data.
%%
{{tpl_movie
	title="A Civil Action"
	image="a_civil_action_poster.jpg"
	author="Jonathan Harr"
	country="United States"
	language="English"
	published="1998-12-25"
	runtime="115 minutes"
	starring= ...
}} 
%%

**action/tpl_movie.php**
%%(php)
<?php

if (!defined('IN_WACKO'))
{
	exit;
}

$info = <<<EOD
Description:
	Displays a movie info box.

Usage:
	{{movie
		title="The Movie Title"
		image="movie_poster.jpg"
		author="Author Name"
		country="Country"
		language="Language"
		published="2022-02-25"
		runtime="120 minutes"
		starring= ...
	}}
EOD;

//  set defaults
$help		??= 0;
$title		??= '';
$image		??= '';
$author		??= '';
$country	??= '';
$language	??= '';
$published	??= '';
$runtime	??= '';
// ...

if ($help)
{
	$tpl->help	= $this->help($info, 'tpl_movie');
	return;
}

// args


// display movie infobox
{
	$tpl->enter('m_');

	// $tpl->var	= $var or function with $var;
	$tpl->title		= $title;
	$tpl->image		= $this->link('file:/' . $image, '', $text);
	$tpl->author	= $author;
	$tpl->country	= $country;
	$tpl->language	= $language;
	$tpl->published	= $published;
	$tpl->runtime	= $runtime;
	// ...

	// include another action
	# $tpl->include		= $this->action('tpl_' . $name, $param);

	$tpl->leave(); // m_
}

%%
**action/template/tpl_movie.tpl**
%%
[ === main === ]
	[ ' help ' ]
	[= m =
		<table class="usertable">
			<tr>
				<th>Title[ ' _t: Title ' ]</th>
				<td>[ ' title ' ]</td>
			</tr>
			<tr>
				<td colspan="2">[ ' image ' ]</td>
			</tr>
			<tr>
				<th>Author[ ' _t: Author ' ]</th>
				<td>[ ' author ' ]</td>
			</tr>
			<tr>
				<th>Country[ ' _t: Country ' ]</th>
				<td>[ ' country ' ]</td>
			</tr>
			[ ' // more here ... ' ]
		</table>
			
		[ '' include // <--- output of Template sub-action '' ]
	=]
%% 

=====Example=====

{{tpl_movie
	title="A Civil Action"
	image="a_civil_action_poster.jpg"
	author="Jonathan Harr"
	country="United States"
	language="English"
	published="1998-12-25"
	runtime="115 minutes"
	starring= ...
}} 

====Formatter====
``
%%(tpl_movie)

title		= A Civil Action
image		= a_civil_action_poster.jpg
author		= Jonathan Harr
country		= United States
language	= English
published	= 1998-12-25
runtime		= 115 minutes
starring	= ...

%%
``

%%(php)
<?php

if (!defined('IN_WACKO'))
{
	exit;
}

// set defaults
# $options['type']	??= 'none';

// get data
$lines	= preg_split('/[\n]/u', $text);
$item	= [];

foreach ($lines as $line)
{
	// blank
	if (preg_match('/^#|^\s*$/u', $line))
	{
		continue;
	}

	$_item = explode('=', $line);
	{
		// debug line
		#Ut::debug_print_r($item);

		$items = [
			'author',
			'country',
			'description',
			'image',
			'language',
			'published',
			'runtime',
			'title',
			// ...
		];

		$key = trim($_item[0]);

		if (in_array($key, $items))
		{
			$item[$key] = $_item[1];
		}
	}
}

// debug item
#Ut::debug_print_r($item);

// display movie infobox
{
	$tpl->enter('m_');

		// $tpl->var		= $var or function with $var;
		$tpl->title			= $item['title'];
		$tpl->image			= $this->link('file:/' . $item['image'], '', 'nixda');
		$tpl->author		= $item['author'];
		$tpl->country		= $item['country'];
		$tpl->language		= $item['language'];
		$tpl->published		= $item['published'];
		$tpl->runtime		= $item['runtime'];
		// ...

		#$tpl->description	= $this->format($description, 'wiki', ['post_wacko' => true]);


	// include another action
	# $tpl->include		= ...;

	$tpl->leave(); // m_
}
%%

**formatter/highlight/template/tpl_movie.tpl**
%%
[ === main === ]
	[= m =
		<table class="usertable">
			<tr>
				<th>Title[ ' _t: Title ' ]</th>
				<td>[ ' title ' ]</td>
			</tr>
			<tr>
				<td colspan="2">[ ' image ' ]</td>
			</tr>
			<tr>
				<th>Author[ ' _t: Author ' ]</th>
				<td>[ ' author ' ]</td>
			</tr>
			<tr>
				<th>Country[ ' _t: Country ' ]</th>
				<td>[ ' country ' ]</td>
			</tr>
			[ ' // more here ... ' ]
		</table>
			
		[ '' include // <--- output of Template sub-action '' ]
	=]
%% 

=====Example=====
%%(tpl_movie)

title			= A Civil Action
image		= a_civil_action_poster.jpg
author		= Jonathan Harr
country		= United States
language		= English
published		= 1998-12-25"
runtime		= 115 minutes"
starring		= ...

%%

----

{{backlinks}}