I created this plugin because of a well-known topic on these forum; the ’limits’ of the default templating methods available.
There are even some modx specific templating libraries floating around like Chunk TPL but I thought why not use a existing templating engine.
I think TBS fits more into ModX than Smarty (imho is nice but to bloathed) and it also forces the designer to use valid (x)html markup.
Name: TinyButStrong Template Engine Plugin (TBS4Modx)
Version: 1.1.1
Author: Armand "bS" Pondman (
[email protected])
Updated: June 22, 2006 14:26 CET
Description:
Use the TBS templating syntax anywhere in your chunks/templates.
Usage:
The variable delimitters are [{variable}] (instead of the default according to TBS manual: [variable])
Document objects and placeholders are available as [{doc.variable}] and [{ph.variable}].
See TBS manual for syntax explanation (
http://www.tinybutstrong.com/).
Special Note:
Because of the way most snippets do there ’templating’ not all is possible in chunks that are renderd in the snippet itself unless the snippet uses the TBS engine in the code.
Quick Installation and Setup quide:
1) Download and extract the archive.
2) Create a directory called "tbs4modx" in your [MODx Directory]/assets/plugins directory
3) FTP or copy the files into [MODx Directory]/assets/plugins/tbs4modx
4) a. Create a new plugin in the manager called "TBS4Modx" and copy/paste the contents of tbs4modx.plugin.txt into the code field.
b. Check the "OnWebPageInit" and "OnWebPagePrerender" event
(optional: if you have a php5 setup you can replace the include of tbs_class.php with tbs_class_php5.php)
Update for plugin code 1.1.1:
/*
* Name: TinyButStrong Template Engine Plugin (TBS4Modx)
* Version: 1.1.1
* Author: Armand "bS" Pondman ([email protected])
* Updated: June 22, 2006 14:26 CET
*
* Description:
* Use the TBS templating syntax anywhere in your chunks/templates.
*
* Usage:
* The variable delimitters are [{variable}] (instead of the default according to TBS manual: [variable])
* Document objects and placeholders are available as [{doc.variable}] and [{ph.variable}].
* See TBS manual for syntax explanation (http://www.tinybutstrong.com/).
*
*/
## Hide error messages (errors will show up in event log)
$tbs_hide_errors = true;
### DO NOT EDIT BEL0W THISE LINE
include_once $modx->config['base_path'] . "assets/plugins/tbs4modx/tbs_class.php";
include_once $modx->config['base_path'] . "assets/plugins/tbs4modx/tbs4modx.class.inc.php";
$e = &$modx->Event;
switch($e->name) {
case 'OnWebPageInit':
# create tbs object
$modx->tbsTpl = new TBSModx('[{,}]','xxx_');
$modx->tbsTpl ->NoErr = $tbs_hide_errors;
break;
case 'OnWebPagePrerender':
# take current modx output and use it as a template for tbs
$modx->tbsTpl->Source = $modx->documentOutput;
# merge added templates with fields/blocks
$modx->tbsTpl->MergeAdded();
# add document objects
$modx->tbsTpl->MergeField('doc','tbsGetDo',true);
# add placeholders
$modx->tbsTpl->MergeField('ph','tbsGetPh',true);
# add POST vars
$modx->tbsTpl->MergeField('post',$_POST);
# add GET vars
# overwrite modx output with tbs handled output
$modx->documentOutput = $modx->tbsTpl->Render();
break;
default:
return;
break;
}
Changelog:
* June 22, 2006 -- version 1.1.1
- add: toggle debugging for errors in event log
set $tbs_hide_errors to true or false (default to true)
TBS templating examples:
Date markup: [{doc.createdon;frm='dd.mm.yyyy hh:nn:ss'}]
takes created on value and displays it in the defined format
also see:
http://www.tinybutstrong.com/examples.php
For snippet developers: How to use the TBS templating in your snippet
First be sure to understand how to use TBS in php without modx (see
http://www.tinybutstrong.com/manual.php’ The TBS plugin uses a special wrapper for the TBS class with some extra methods you’ll be using in snippets. More documentation coming up but I tried to make a code example to clear some things up
$template = $modx->tbsTpl->addTemplate($mysnippet_template);
$modx->tbsTpl->addField($template,'myvariable',$myvariable);
$modx->tbsTpl->addBlock($template,'myarray',$myarray);
$output = $template;
$modx->tbsTpl->addTemplate( [b]string Template )[/b]
used for loading your template (string containing html and tbs tags)
returns a template id/placeholder
$modx->tbsTpl->addField(string TemplateID, string BaseName, mixed X}
$modx->tbsTpl->addBlock(string TemplateID, string BaseName, mixed X}
addField and
addBlock are almost identifical to TBS methods MergeField and MergeBlock except they take the template id returned by addTemplate as first argument
That’s all be sure that your snippet adds the template id (in the example case called $template) to it’s output back to modx
History:
* June 19, 2006 -- version 1.1.0
- added: new release of TBS classes 3.10
- fix: couple of small ’bugs’
- code cleanup
* June 15, 2006 -- version 1.0.2
- fixed: error when no block or field existed
- fixed: removed <php in the plugin code
* June 14, 2006 -- version 1.0
- added: wrapper class for use in snippets
- added: POST and GET values