Categories > TinyButStrong general >

Wrapping LoadTemplate in another function

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: martijn
Date: 2006-12-26
Time: 10:21

Wrapping LoadTemplate in another function

Hi,
I'd like to make a wrapper for the LoadTemplate function, that does not lose it's functionality. This is because I have a constant containing the path to the template directory so that people would only have to specify the template file. I've got an idea on how to make this work but am not sure, something like this:
function Template($tpl){
global $tmpl; // My variable for TBS calls
$tmpl->LoadTemplate(TPL_PATH.'$tpl'); // In my case TPL_PATH is 'template/'
/* ... Not sure what to do after this, a return or something? ...*/
}
Can anybody help me out with this? Thanks in advance!
By: Skrol29
Date: 2006-12-28
Time: 00:03

Re: Wrapping LoadTemplate in another function

Hi,

This wrapper can be done with a TBS plug-in.
As is it quite simple, you can do it with a function instead of a class.
Here is an example of how it can be coded.
More information about coding plug-ins:
  http://www.tinybutstrong.com/manual.php#plugins

$TBS->PlugIn(TBS_INSTALL,'TplFld');
...
function tbspi_TplFld_BeforeLoadTemplate(&$File,&$HtmlCharSet) {
   $File = TPL_PATH.$File;
}
not tested, but you've got the idea.
By: martijn
Date: 2006-12-28
Time: 08:37

Re: Wrapping LoadTemplate in another function

Hi, thanks for your reply but I get this error:
TinyButStrong Error with plug-in 'TplFld' : no class named 'TplFld' is found, and no function named 'tbspi_TplFld_OnInstall' is found.
I've not really been working with coding TBS plug-ins yet, so it's a bit hard for me to understand.
By: sheepy
Date: 2006-12-28
Time: 09:16

Re: Wrapping LoadTemplate in another function

I simply warp the whole TBS with functions, all the way from loading template to displaying them.  I hate forgetting the & sign in PHP4, functions needs no global var declaration and works really nice with code completion, plus it solves questions like yours.
By: Skrol29
Date: 2006-12-28
Time: 10:44

Re: Wrapping LoadTemplate in another function

Hi,
I forgotten this little function needed to install the plug-in:
function tbspi_TplFld_OnInstall() {
   return array('BeforeLoadTemplate');
}
By: martijn
Date: 2006-12-28
Time: 17:40

Re: Wrapping LoadTemplate in another function

Thanks a bunch, it works now! :)
Makes things much easier!
By: martijn
Date: 2006-12-29
Time: 07:36

Re: Wrapping LoadTemplate in another function

I know I should open a new thread so I hope you don't mind me posting it anyway.
I'm trying to implement a tags function for my site.
The tags are stored in a MySQL row called 'tags', like this: tag1 tag2 tag3 (so they're separated by spaces).
I'm able to put these tags in their own array:
$tag[] = 'tag1';
$tag[] = 'tag2';
...
But when I try to list them in my template, they do get listed, but the element that is specified in 'block=' is added after the official end of the array. <li>tag1</li> <li>tag2</li> |>| <li></li> |<| for example.
Here's the PHP code:
    $select = mysql_query("SELECT tags FROM `files_releases` WHERE 1"); // Get all tags
    while ($line = mysql_fetch_array($select, MYSQL_ASSOC)) {
        $adds.= $line["tags"]." "; // Put the tags into variables
    }
    $adds = explode(' ',$adds);
.......   
$tmpl->MergeBlock('arry',   $adds);
Thanks in advance!