Categories > TinyButStrong general >

a diff way of including sub-templates

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Mankiy
Date: 2003-07-20
Time: 02:18

a diff way of including sub-templates

will it replace variables in a sub-template if i do this?:


PHP:
<?php

\\all that code and stuff

$header = include("header.tpl");

$PAGE->assign("HEADER", "$header");


and if i did that, would it replace the template variables inside that sub-template?
By: Skrol29
Date: 2003-07-20
Time: 03:42

Re: a diff way of including sub-templates

What you're triing to do is possible, but I don't undestrand your code.

The Php function include() return nothing.
And ->assign() is not a TBS's method. It looks like a Smarty's or a SmartTemplate's method.

With TBS you can do this :
(assuming that $header is te content of the header.tpl file)

Php : $TBS->MergeField('header',$header) ;
Html : [header;htmlconv=no]

There is a smarter way :
Php : //nothing special
Html : [tbs_inculde.onload;file=header.tpl]

The sub-template can contains variables, blocks... what you want and it will be processed just like it was a main template.
By: Mankiy
Date: 2003-07-20
Time: 04:06

Re: a diff way of including sub-templates

yeh, i know 0_o

i havent looked at much of my PHP right now, mainly working on templates atm 0_o, so im bound to have some things wrong.....

and i got a question.....

the variables in the sub-template, am i able to replace them from the main file......

like this:
PHP:
$PAGE->MergeField("subtemplatetitle", $title);

main html file:
[tbs_inculde.onload;file=header.tpl]
thats the Title up there, oh joy
</body>
</html>

sub html file:
<html>
<head>
<title>[subtemplatetitle]</title>
</head>
<body>
<b>[subtemplatetitle]</b>
By: Skrol29
Date: 2003-07-20
Time: 04:38

Re: a diff way of including sub-templates

It will work better with :

main html file:
[tbs_include.onload;file=header.tpl;htmlconv=no]
thats the Title up there, oh joy
</body>
</html>

'htmlconv=no' is very usefull in your case because TBS try to include only the body part by default.
Other code are ok.

Some tips :

1:
Instead of
  $PAGE->MergeField("subtemplatetitle", $title);
you can just use [var.title] in the sub-template and all is automatic.
[var.title] will work in the main template and the sub template as well.

2:
If you need, thename of the file can be stored in a php variable.
For example:
[tbs_include.onload;file=[var.header];htmlconv=no]