Summary: insert dynamic contents in your pmWiki page using TinyButStrong
template engine version 3.2.0 or higher
Status: in active use
Categories: Content Management System Add-Ons
Questions answered by this recipe
- How to display data retrieved from MySql tables?
- How to get and manage data given by a user form?
- How to embed a PHP application in a pmWiki site?
Or more generally: how to insert dynamic content inside a pmWiki page ?
This cookbook allows to insert some HTML dynamic content build from a PHP script. The PHP script must use the TBS template engine (TBS means TinyButStrong) to be functional because the cookbook takes the content directly produced by TBS. The final HTML content is actually inserted when the pmWiki page is displayed. There is no insertion using HTML iframe, nor HTML objects.
This cookbook does not make learning TBS easier, it just makes easier to use TBS for pmWiki pages.
If you don't know TBS here is a small description:
TinyButStrong is a PHP template engine which enables you to easily build dynamic contents using WYSIWYG templates.
It is one file with a PHP class having only 6 methods and 5 properties.
- Put the TBS class file (tbs_class.php) in your cookbook directory, or in the same directory as your PHP script.
The tbs_class.php file is available with the TinyButStrong standard distribution, here.
- Put tbs_plugin_pmwiki_2.02.phpΔ in your cookbook directory.
- Edit your config.php as following:
- Add include("cookbook/tbs_plugin_pmwiki.php"); or include("
- Add $TbsScriptToCall['my_alias'] = 'my_script.php';
Do the same for each script that you allow to be inserted in pmWiki pages.
- As an option, you can define $TbsScriptToCall['path'] = 'my_dir/';
This specifies the directory where all TBS scripts are stored, relatively to the pmWiki root.
- Do not include the tbs_class.php in the config.php file. It is better to include it from your PHP script.
Example of lines added in config.php:
$TbsScriptToCall['path'] = 'my_tbs_app/';
$TbsScriptToCall['customers'] = 'customers.php';
$TbsScriptToCall['regions'] = 'regions.php';
$TbsScriptToCall['products'] = 'products.php';
Since the cookbook is installed, and you have defined all alias corresponding to the PHP scripts, the content can be insterted using a markup:
See under to know more about how the TBS scripts should be coded for pmWiki.
With previous versions 1.x of this cookbook, you should write:
You can limit the placement of a content for only one pmWiki page by doing like this in the config.php file:
if (pagename='Admin.Products') $TbsScriptToCall['products'] = 'products.php';
How to code a TBS script to be inserted into a pmWiki page
This section assumes that you know the TinyButStrong template engine.
Some doc, examples and forum are available at TinyButStrong.
They are some characteristics for the TBS script and the HTML template when you use them with the current PmWiki Cookbook:
- You can use the tag
[var..pmwiki_url] in your TBS template to display the link to the current pmWiki page.
With the cookbook version 1.x, you can only use
[var..pmwiki_page] which return the full URL with all arguments.
- The LoadTemplate() TBS method will also search the template file in the path that you have defined in config.php using $TbsScriptToCall['path'].
- The script must ends with $TBS->Show();. At least it should not do anything about the content after this line.
- Never use the command exit(); in your PHP script.
- Please note that when the script is running under pmWiki, then variables will be local by default instead of global. This is because pmWiki calls the script within a function. TBS [var] fields may display error unless you have explicitly declared those variables as global (i.e0 using the PHP command 'global').
- With PHP 4.x, you must create the TBS object by reference (see below).
Example of a simple script using TBS:
// MySQL connection
// The TinybutStrong class
// Instantiate the TBS class
$TBS =& new clsTinyButStrong;
// Load the template.
// The path is relative to the current PHP script or the PmWiki root
// Merge data
$TBS->MergeBlock('c','mysql','SELECT* FROM t_customer ORDER BY name');
// Display the result, which is redirected in the pmWiki page by the cookbook
If your script should not be run in standalone (outside a pmWiki page) then add the following line in the script:
if (!defined('PmWiki')) exit();
|2007-03-26||1.03||Better management of <pre> tags and allows several arguments in the pmWiki|
|2008-05-10||2.00||* The content is inserted as is, no pmWiki markup are processed over the part of the content which is inserted.|
* New TBS tag [var..pmwiki_url]: it is valid for both PathInfo modes, and return the URL of the current PmWiki page without extra parameters.
* Bug fixed: templates without any <body> tags are now supported.
|2010-02-02||2.01||Works with TBS version >= 3.5.0|
|2010-02-04||2.02||optimize the time for inserting the content in the pmWiki page|
In the TBS script, the creation of the TBS instance must be done by reference (using =&) when you use PHP 4.x. Otherwise, the plug-in won't work and you will have a blank content inserted in your pmWiki page.
$TBS =& new clsTinyButStrong;
User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.