Categories > TinyButStrong general >

include with MergeBlock

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Manuel
Date: 2007-06-26
Time: 15:29

include with MergeBlock

Hello!

I have the following problem and I could not find a good answer yet. Perhaps you can help me.

I have a file, named index.php. At the end of this file I call the LoadTemplate-function:
$TBS->LoadTemplate('index.tpl', FALSE);

Just before I call this function I am including other php-scripts. In these other scripts I have a variable, called $tmpl_include, which is set in the index.tpl to have a dynamic subtemplate:
[onload;file=[var.tmpl_include]]

This works fine, but if i do MergeBlock in these sub-PHP-scripts, it doesn't work because these scripts are includet before the LoadTemplate-function is called.
How to include correctly, so that I don't need to write the MergeBlock-Statements into my index.php for my whole website?

I am sorry for my bad english.

Thank you very much for answering!
Nice greetings from Germany,
Manuel
By: Skrol29
Date: 2007-06-27
Time: 13:37

Re: include with MergeBlock

Hello Manuel,

You can do it in several ways.

The more simple is to define $tmpl_include as a global variable in your subscript. This way it should be processed correctly with the tag
[onload;file=[var.tmpl_include]]
global $tmpl_include;
$tmpl_include = '...';
  or
$GLOBALS['mpl_include'] = '...';

If $TBS, the instance of the class, exists already when you subscript is run, then you can also pass the value to merge by the $TBS->TplVars array or the $TBS->ObjectRef object.

Example:
$TBS->TplVars['tmpl_include'] = '...'

[onload;file=[var..tplvars.tmpl_include]]
By: Manuel
Date: 2007-07-01
Time: 01:24

Re: include with MergeBlock

Thanks for your answer Skrol!

I am not really sure if this can solve my Problem, but I will think about that.

What I want to do is somethink like this:

$TBS->MergeBlock(...);
$TBS->MergeBlock(...);
$TBS->LoadTemplate(...);
$TBS->Show();

The MergeBlocks are called before I can load the template because LoadTemplate is called in my index.php and all my other files are included just before loading the template. And TplVars could help me with this?

What I also think about is to stop including files from 1 index.php and using many files with an overall header and footer...but there I have always problems with the path of the files...

Thank you very much for your help,
Manuel
By: Skrol29
Date: 2007-07-04
Time: 01:10

Re: include with MergeBlock

Hi,

I think I see what you mean now.
There are several ways to do this.
I simple way is to define a function in your sub-script which performs the task and which will be called later in the main script.

Another way is to do as the following example. The subscript stores TBS task to perform into an array, and then the main script will call each tasks of the array. This enables your sub-scripts to add task or not.

main.php:

$TBS = new clsTinyButStrong;
$tbs_tasks = array();

include('page_x.php');

$TBS->LoadTemplate('index.tpl', FALSE);

foreach($tbs_tasks as $task) {
  call_user_func_array($task['fct'],$task['args']);
}

$TBS->Show();


page_x.php:
// Define the main template to load
$tmpl_include = 'page_x.html';

// add a task to perform later
$meth = array(&$TBS,'MergeBlock');
$args = array('blk','mysql','SELECT * FROM table1');
$tbs_tasks[] = array('meth'=>$meth, 'args'=>$args);

If your tasks are more complicated then you'd better to insert a TBS script instead of a file. See parameters "script" and 'subtpl".
By: Manuel
Date: 2007-07-04
Time: 01:29

Re: include with MergeBlock

Hi Skrol,

many thanks! That's what I meant. I thought there would be a better solution, but this is also okay, thank you very much!

Another general question: Do you prefer 1 index.php and include from this file all other pages or is it better to have many files with includes for a header and a footer? I always used the first opinion, but phpbb uses the second one. Perhaps one of these opinions is better for using a template engine?

Thank you very much for everything,
Manuel