Formatter: Content Templates
1. Multi-line actions and formatters
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/ |
So you can write your own actions or a dedicated formatter which parses your predefined syntax.
-
{{tpl_name param... }} -
%%(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 and translation, or not.
- WackoWiki Markup[link1]
- Usage of Template Engine[link2]
To make this approach expandable to whatever you like we just should treat wiki-pages as data objects.
Then one can use as I have mentioned before or any other kind of a new tool to work with such objects.
We have already page_langVARCHAR(5)in pages table - to set language, and formattingVARCHAR(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. -- Elar9000[link3]
2. How to write your own content templates.
Very simple example without advanced array usage, functions, styles or filters.2.1. 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
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 '' ] =]
2.1.1. Example
Unknown action
tpl_movie2.2. 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
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 '' ] =]
2.2.1. Example
| Title | A Civil Action |
|---|---|
![]() |
|
| Author | Jonathan Harr |
| Country | United States |
Referring pages:
- Comment4275[link4]
- Dev/PatchesHacks[link5]
- Dev/PatchesHacks/TemplateInsert[link6]
- Dev/Release/R6.1/MultiLineActionsAndFormatters[link7]
- [link1] https://wackowiki.org/doc/Doc/English/Markup
- [link2] https://wackowiki.org/doc/Dev/Projects/Templatest/Usage
- [link3] https://wackowiki.org/doc/Users?profile=Elar9000
- [link4] https://wackowiki.org/doc/Comment4275#a-4392
- [link5] https://wackowiki.org/doc/Dev/PatchesHacks#a-4392
- [link6] https://wackowiki.org/doc/Dev/PatchesHacks/TemplateInsert#a-4392
- [link7] https://wackowiki.org/doc/Dev/Release/R6.1/MultiLineActionsAndFormatters#a-4392
