Categories > TinyButStrong general >

Subtemplates

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Shaps
Date: 2007-03-20
Time: 15:31

Subtemplates

Hi,

I've a problem with subtemplate. I want to get the same result than PHP include function

So I've a main page (index.php with index.tpl) in this page I've some links with a 'Cat' parameter: http://mysite/index.php?Cat=News. I want to include the News.tpl in the main.tpl. I've tried a lot of code to do this but still the same error:

TinyButStrong Error in field [var.title_page...] : the PHP global variable named 'title_page' does not exist or is not set yet. This message can be cancelled using parameter 'noerr'.

if I declare the $title_page in the index.php it seems to be ok but I don't want to write all the code in this page...

What's the best way to get rid of this error?

index.tpl:
<html>
<head></head>
<body>
  [onshow;script='news.php';subtpl]
<body>
</html>

index.php
require_once "./tbs_class.php";
$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate(“index.tpl”);
$TBS->Show();

News.tpl:
<html>
<head></head>
<body>
  [var.page_title]
<body>
</html>

News.php:
require_once "./tbs_class.php";
$page_title = "News Title Page"
$this->LoadTemplate("news.tpl");
$this->Show();
By: TomH
Date: 2007-03-20
Time: 16:53

Re: Subtemplates

There seems to be code missing to do what you ask... is this what you're trying to do...

Clicking:
http://mysite/index.php?cat=News

index.php:

$filetouse= $cat.".php";

require_once "./tbs_class.php";
$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate(“index.tpl”);
$TBS->Show();

index.tpl:
<html>
<head></head>
<body>
  [var.filetouse;script=[val];subtpl]
<body>
</html>


News.php:
require_once "./tbs_class.php";
$page_title = "News Title Page"
$this->LoadTemplate("news.tpl");
$this->Show();

News.tpl:
<html>
<head></head>
<body>
  [var.page_title]
<body>
</html>

Am I understanding yet?

By: Shaps
Date: 2007-03-20
Time: 17:31

Re: Subtemplates

Hi,

Yes this is what I'm trying to do but it doesn't work. I removed some part of code to clear the post but it's exactly what I want to do. I've tried your code and I get the same error... The subtemplate appears but the [var.page_title] is not replaced by the value...

I think it's a very basic feature but I don't find the way to get the good result...

Thanks for your comments
By: TomH
Date: 2007-03-20
Time: 21:37

Re: Subtemplates

Please take this in good spirit...
It seems that you are asking for us to read your mind on this... please just post the exact code, not pseudo-code, or we cannot help you debug without endless back-and-forth posts.
By: Shaps
Date: 2007-03-21
Time: 09:45

Re: Subtemplates

Ok,

Sorry for my first post. I've found a solution but I don't now if it's the best way to my problem.

index.php
<?php
    include_once('./tbs_class_php5.php') ;

    $templatepath = "templates/";
   
    if(isset($_GET['Cat']) && !empty($_GET['Cat']))
    {
        switch($_GET['Cat'])
        {
            case "News":         $tmpl_page = "news.php";
                              break;
                                       
            default: $tmpl_page = "principal.php";
        }
    }
    else
        $tmpl_page = "principal.php";
   
    $TBS = new clsTinyButStrong ;
    $TBS->LoadTemplate('templates/index.tpl');
    $TBS->Show();
?>

Index.tpl
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
    <head>
        <title></title>
    </head>
   
    <body>
    <div id="conteneur">       
        <div id="menustart"></div>
        <div id="menuend"></div>
            <ul id="menu">
                <li><a ref="index.php?Cat=News">News</a></li>
            </ul>
        </div>
       
        [onload;script=[var.tmpl_page];subtpl]
       
        <p id="footer">SRInformatique</p>
    </div>
    </body>
</html>

News.php
<?php
    include_once('./check_tbs.php') ;
   
    $GLOBALS['tmpl_title'] = "News";
    $TBS->LoadTemplate('templates/news.tpl');
    $TBS->Show();
?>

News.tpl
<div id="contenu">
    <h2>[var.tmpl_title]</h2>
</div>

check_tbs.php
<?php
    include_once('./tbs_class_php5.php') ;
    if(isset($this))
        $TBS =& $this;
    else
        $TBS = new clsTinyButStrong;
?>

thanks for the support
By: TomH
Date: 2007-03-21
Time: 13:42

Re: Subtemplates

Looks good to me.

I see you got a way to get the TBS instance to continue, that always catches me out a bit :)

Some simplification might be done - probably not required...
$_GET['Cat']="News" ? $tmpl_page = "news.php" : $tmpl_page = "principal.php";

=======  replaces ===========

if(isset($_GET['Cat']) && !empty($_GET['Cat']))
{
  switch($_GET['Cat'])
  {
   case "News":   $tmpl_page = "news.php";
            break;
        
   default: $tmpl_page = "principal.php";
  }
}
else
  $tmpl_page = "principal.php";

Otherwise no help needed as far as I can see :)
By: Shaps
Date: 2007-03-21
Time: 14:21

Re: Subtemplates

Ok,

If I understand I always need to declare the template's var as global in my PHP code. What's wrong in getting the TBS instance to continue? Is there a better way? I read that multiple instance of TBS could reduce the performance...

Thanks
By: TomH
Date: 2007-03-21
Time: 14:49

Re: Subtemplates

I didn't mean something wrong -- just that I tend to forget to take care of that myself :)