Categories > TinyButStrong general >

Nested Templates

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Nicolaus
Date: 2006-12-04
Time: 20:09

Nested Templates

I have a sidebar in my design where I have blocks with different designs i.e. a Calendar, Archive Link, Login, etc.
These blocks can be assigned by the user in different sections i.e. Right Sidebar, Left Sidebar, Header, Sub Footer.
I could not figure out, how I can merge different (dynamic) templates into my sections of the design.

 
By: Skrol29
Date: 2006-12-04
Time: 20:49

Re: Nested Templates

He you seen how subtemplates and subscripts work with TBS ?
There are online examples at the Examples page.
By: Nicolaus
Date: 2006-12-04
Time: 21:46

Re: Nested Templates

Yes I did, but how do I manage an "unknown" number and type of subtemplates into the main template? What do I'm not getting here?
By: Skrol29
Date: 2006-12-04
Time: 21:56

Re: Nested Templates

The principle idea is this:
$widgets = array('./widgets/w1.php','./widgets/w2.php',...);
$TBS->MergeBlock('w',$widgets);
HTML:
<div>[w.val;block=div;script=[val];subtpl]</div>

Since you have this, you can play with it in order to displatch the display of your widgets to different parts of your page (header/footer/...). I suggest that you use sub-blocks (parameter p1).

By: Nicolaus
Date: 2006-12-04
Time: 22:13

Re: Nested Templates

Thank you very much ... I have tried exactly this ... but now I'm running into the problem, that I need to keep conflicting variables global ...

What I was hoping for, was that I can "process" MergeBlock, assign the result to an array and use this array in the main template or the subtemplate representing the sidebars and other sections.

Thanks for your input!



By: Nicolaus
Date: 2006-12-04
Time: 22:48

Re: Nested Templates

Hmm, I believe I found the solution ;-)

$TBS->Show(TBS_NOTHING)
$RenderResult[BlockSection] = $TBS->Source;

$RenderResult is a global array in my program.

I keep testing, and it looks good so far :-)


By: TomH
Date: 2006-12-05
Time: 02:11

Re: Nested Templates

Nicolaus,
There is another approach to this as well (with a lot of help from Skrol29 to get it working) - in your user data incorporate the column and sequence data records to use when populating the main template. The actual content definition comes from the subtpl scripts also defined in the records

See example here http://tomhenry.us/tbs3/ )the prototype CMS link there)
In the  php code I do something like...
// get the modules and create layout using position (columns) defs and sequence defs                           
$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 ";
$db->get_results($sql123);
//$ezdebug .= $db->debug();
$TBS->MergeBlock('blk',$db);

The main layout template (html) looks something like...
<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 portion of the block def...
<td class="[blk.category]">[blk.id;script=[blk.categurl];subtpl;block=table]</td>
does the work putting each subtpl script in the correct location and the subtpl script itself what queries for the content.

In the above, when the value of script=blk.categurl="module_contentquery.php" the subtpl code looks like (using TBS very nice "subquery" feature)...
$this->LoadTemplate("module_contentquery.html");  // use generic sidebar template

$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);
//$db->debug();

$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() ;

And the html TEMPLATE using the query/subquery like this...
<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>

I hope that is clear enough - glad to help more if you want to try this.