Categories > TinyButStrong general >

use multible templates with multible loadtemplate()?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: tobi
Date: 2006-10-27
Time: 14:56

use multible templates with multible loadtemplate()?

hi,
my website is complety based on the data of a mysql database.
i use modrewrite and a script to get my templates with a query.
but i have the following problem:
1 template is for the whole site and then are further "subtemplates", there will get the content. the content is variable, one site can have 5 "subtemplates" with content out of the db.
so it is impossible to create with a script one template, because in the subtemplates maybe use the same vars.
now i have the idea, to load the class at the beginning of the script and load the "subtemplates" in with foreach:
$TBS = new clsTinyButStrong;
$TBS->LoadTemplate('get.......'.tpl');
$TBS->Render = TBS_NOTHING;
$TBS->Show();
$content[$i] = $TBS->Source;
than get the template of the whole site and get the content into the site.

Do you know a better way? how will the performace be?

Thanks for help!

to make it more clear:
whole site template
-> content in between (textfield)
-> content in between (galary)
-> content in between (textfield)
-> content in between (big picture)
-> content in between (textfield)
whole site template
By: Skrol29
Date: 2006-10-27
Time: 16:54

Re: use multible templates with multible loadtemplate()?

Hi,

Creating and managing a second instance of TBS is not good for performance. That's why the subtemplate mode has been made.

If the problem is about [var] fields in your subtemplates, then you can declare wanted var as global in your subscript.

Another solution is to place [onload;file=[var.subtpl1]] in the main template. And then, manage subtemplate parts with the global $TBS instance like this:
Main script :
if (...) $subtpl1 = ... $subscript1 = ...
if (...) $subtpl2 = ... $subscript2 = ...
...
$TBS = new clsTinyButStrong;
$TBS->LoadTemplate('main'.tpl');
include($subscript1);
include($subscript2);
...
$TBS->Show();

Subscript :
$zzz = ...
$TBS->MergeBlock(...);

By: TomH
Date: 2006-10-27
Time: 19:29

Re: use multible templates with multible loadtemplate()?

Another approach...
I have a CMS prototype where I use TBS subquery feature to nice advantage. For modules (tbs subscripts) that get content from database I have database record for that module and in that record is also the $SQL stmnt that is used by TBS subquery to get the content records for that specific module.

Only one main script does all of the work like this
index.php
// get the COL modules and create layout using  GROUPS (items that are ((not content))                                   
$sql123 = "select id,type,position,sequence,category,categurl,descript from $main_table WHERE type='column' AND publish = 'all'  ORDER BY position ASC, sequence ASC, changed DESC "; //LIMIT 0,5";
$db->get_results($sql123); // ezSQL database class used here
//$db->debug();
$TBS->MergeBlock('blk',$db);

And the template index.html
<table width="99%" border="0" align="left"
cellpadding="0" cellspacing="0">
        <tr>
   
        <!-- n.b. no use of "headergrp" just parentgrp to get the cols to repeat td for each table-->
        <td class="col_[blk.position]" width="200" valign=top>
               
        <!-- [blk.position;block=td;parentgrp=position] -->        
        
                <table  class="[blk.position]" width="100%" cellspacing="0" cellpadding="0" border="0">
                <tr>
                <td class="[blk.category]">[blk.id;script=[blk.categurl];subtpl;block=table]</td>
                </tr>
                </table>
          </td>
        </tr>
        </table>

In the above the database record includes the name of the subtemplate to use i.e.  "blk.categurl" = "module_contentquery.php"

Each of the modules using subquery look like this example...
module_contentquery.php
$this->LoadTemplate("module_contentquery.html");
$sql = "SELECT id AS mainid,descript AS mainlabel, intro AS maincontent, categsql AS mainsql from $main_table where publish='all' and type='module' and position='contentquery' ORDER BY sequence";

$db->get_results($sql);

$this->MergeBlock('main',$db);         // MAIN --use the subquery feature of TBS
$this->MergeBlock('sub',$db, '%p1%');  // SUB  --subquery will come from the database 

$this->Show() ;

The above db query gets also the $SQL  from the db record that is used in the template when block is merged...
module_contentquery.html
<table class="module" width="100%" border="1" cellspacing="0" cellpadding="3">
<tr><th align=left class="contentquery" ><font color="#008080">[main.mainlabel;htmlconv=no; block=table]</font><br> <!-- font face="normal"  size="-4"> subquery: [main.mainsql]</font --> </th></tr>

<tr><td  class="contentquery" valign="top" nowrap=nowrap>&#8226;<a class="contentquery" href="[var..script_name]?id=[sub.subid;noerr]&show=id&cat=[sub.sublabel;noerr]"> [sub.sublabel; ope=max:24; block=tr;p1=[main.mainsql]]</a></td></tr>

</table>

Hope that helps,
By: tobi
Date: 2006-10-29
Time: 16:55

Re: use multible templates with multible loadtemplate()?

thanks for the suggestions, but it isn´t the solution für problem i am faceing.

the order of the contents in the page is dynamic, this means, i cant use a static template, i would have to generate it dynamic.
that would not be a problem, but what is, if i would load the same subtemplate 2 or 3 times?
the vars would have the same name and i would get the same content 2 or 3 times in the same subtemplate.
to fix this i would have to render all my templates dynamic and add a _1 aso to all fields. any new ideas for that opportunity?

i cant think of another way than my solution in the first post, do you?