Categories > TinyButStrong general >

TBS can not always exactly parse my template file

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Phil
Date: 2013-08-26
Time: 09:40

TBS can not always exactly parse my template file

Hello,

In my project, I define a template class to initial TBS object and reset VarRef to false for used by other classes.

require_once("tbs_class.php");

class template {

    public static function getTemplateInstance() {
        try {
            $_template = new clsTinyButStrong();
            $_template->setOption(array(
                                        'fct_prefix' => 'slc_',
                                        'include_path' => TEMPLATE_DIR,
                                    ));

            $_template->ResetVarRef(false);

            return $_template;

        } catch ( Exception $e ) {
            $mesg = "Initializing Template Object Fail !!";
            echo "<b>$mesg<br/>".$e->getMessage()."</b><p/>";
            site::logMessage(__CLASS__, __METHOD__, $mesg."\n".$e->getMessage());
        }
    }
}

In other classes, there is an inherited template variable to store and access TBS object.

abstract class authorize {

    protected $template = NULL;
    protected $companyInfo = array();
    protected $userInfo = array();

    protected function setItem($name, $value) {
        $this->$name = $value;
    }

    protected function getItem($name) {
        return $this->$name;
    }
}

class collect extends authorize {

     public function __construct() {

        $this->setItem("companyInfo", site::getItem("companyInfo"));
        $this->setItem("userInfo", site::getItem("userInfo"));

        if ( empty($this->userInfo) ) site::sendTo("index", "defaultAction");

        $this->setItem("template", template::getTemplateInstance());

        $this->template->VarRef['userStatus'] = 1;
        $this->template->VarRef['subMenu'] = "collectSubMenu.tpl";

        foreach ( $this->companyInfo as $k => $v ) {
            $this->template->VarRef[$k] = $v;
        }

        foreach ( $this->userInfo as $k => $v) {
            $this->template->VarRef[$k] = $v;
        }
    }

    public function defaultAction() {

        $data = $res = $initem = $tbs = $return = array();
        $total = 0;
       
        /*..... Get Data from DB and Do Some Calculate ..... */

        $this->template->VarRef['jsFile'] = "js/collect.js";
        $this->template->VarRef['totalAmount'] = $total;
        $this->template->VarRef['companyCurrency'] = $this->companyInfo["WAERS"];
        $this->template->VarRef['subPage'] = "collect.tpl";

        if (TPL_DEBUG) $this->tplVarDump();

        $this->template->LoadTemplate("default.tpl");
        $this->template->MergeBlock("lineItem", "array", $return);
        $this->template->Show();
    }
}

When I call above class's defaultAction method, TBS can not always exactly parse my template file.
It will sometimes show "the key xxxx does not exist or is not set in VarRef. (VarRef seems refers to a custom array of values)".
I dump TBS object to check variables passing correctly or not. However, I find that my variables are in TBS's VarRef property as follows.

<b>TPL Var : </b><p/><pre>clsTinyButStrong Object
(
    [Source] =>
    [Render] => 3
    [TplVars] => Array
        (
        )

    [ObjectRef] =>
    [NoErr] =>
    [Assigned] => Array
        (
        )

    [Version] => 3.8.2
    [Charset] =>
    [TurboBlock] => 1
    [VarPrefix] =>
    [VarRef] => Array
        (
            [userStatus] => 1
            [subMenu] => collectSubMenu.tpl
            [BUKRS] => LV1
            [BUTXT] => BUTXT
            [WAERS] => TWD
            [SPRAS] => M
            [KTOPL] => SLC
            [EMPNO] => 12345
            [EMPNAME] => Phil
            [NTID] =>
            [EMPDEPT] =>
            [EMAIL] =>
            [jsFile] => js/collect.js
            [totalAmount] => 21500
            [companyCurrency] => TWD
            [subPage] => collect.tpl
        )

    [FctPrefix] => slc_
    [Protect] => 1
    [ErrCount] => 0
    [ErrMsg] =>
    [AttDelim] =>
    [MethodsAllowed] =>
    [OnLoad] => 1
    [OnShow] => 1
    [IncludePath] => Array
        (
            [0] => /web_site/finance/template/
        )

    [ExtendedMethods] => Array
        (
        )

    [TplStore] => Array
        (
        )

    [_ErrMsgName] =>
    [_LastFile] =>
    [_CharsetFct] =>
    [_Mode] => 0
    [_CurrBlock] =>
    [_ChrOpen] => [
    [_ChrClose] => ]
    [_ChrVal] => [val]
    [_ChrProtect] => &#91;
    [_PlugIns] => Array
        (
        )

    [_PlugIns_Ok] =>
    [_piOnFrm_Ok] =>
    [_UserFctLst] => Array
        (
        )

)
</pre><br /><b>TinyButStrong Error</b> in field &#91;onload.script=...]: the key 'script=' does not exist or is not set in VarRef. (VarRef seems refers to a custom array of values) <em>This message can be cancelled using parameter 'noerr'.</em><br />
<br /><b>TinyButStrong Error</b> in field &#91;onload.>Conten...]: the key '&gt;Conten' does not exist or is not set in VarRef. (VarRef seems refers to a custom array of values) <em>This message can be cancelled using parameter 'noerr'.</em><br />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
    <link href='css/south-street/jquery-ui-1.10.3.custom.css' rel='stylesheet'>
    <script src='js/jquery-1.9.1.js'></script>
    <script src='js/jquery-ui-1.10.3.custom.js'></script>
    <link href='css/theme.css' rel='stylesheet' type='text/css' />
    <title>Project Name</title>
</head>
<body>
   
    <div id='header'>
        <img src='img/slc_logo.png'>
    </div>
    <ul id='sys_menu'>
        <li><a href='?index/defaultAction'>index</a></li>
        <li><a href='?admin/defaultAction'>admin</a></li>
        <li><a href='?collect/defaultAction'>collect</a></li>
        <li><a href='?balance/defaultAction'>balance</a></li>
        <li><a href='?account/defaultAction'>account</a></li>
        <li><a href='?finance/defaultAction'>finance</a></li>
        <li><a href='?sign/defaultAction'>sign</a></li>
        <li><a href='?report/defaultAction'>report</a></li>
    </ul>
    <div id='main_zone'>
        [onload.subMenu;script=showSubTemplate.php;subtpl]
        [onload.subPage;script=showSubTemplate.php;subtpl]
        <div id='footer'>Content is Copyright ShangLoong Corp. 2013.</div>
    </div>
</body>
</html>


Do I make something wrong ?

Any advice to help me in my project is greatly appreciated.
Thank you !

Regards,
Phil
By: Phil
Date: 2013-08-27
Time: 13:29

Re: TBS can not always exactly parse my template file

It seems that TBS can not properly get the variables, i.e. subMenu and subPage, I have set in VarRef property. So that it can not embed the sub-template files.

Is this TBS's bug ?
By: Skrol29
Date: 2013-08-28
Time: 00:16

Re: TBS can not always exactly parse my template file

Hi,

According to the error message above, it seems that you've typed [onload.script=...] instead of [onload;script=...]. (dot instead of semi-colon).
Thus TBS is looking for item 'script' in VarRef.

Does the message happens for other items ?
By: Phil
Date: 2013-08-28
Time: 02:50

Re: TBS can not always exactly parse my template file

Hi Skrol29,

Thanks for your reply !

This kind of problem only happens to my default.tpl. It is the main template in my project.
I use two variables, subMenu & subPage, to control which sub-template should be embedded or not.

Sub-template section in default.tpl is as follow.
<div id='main_zone'>
        [onload.subMenu;script=showSubTemplate.php;subtpl]
        [onload.subPage;script=showSubTemplate.php;subtpl]
        <div id='footer'>Content is Copyright ShangLoong Corp. 2013.</div>
</div>

The content of showSubTemplate.php is as follow.
<?php
$this->loadTemplate($CurrVal);
$this->Show();
?>

Only these two variables use onload method. Other variables use MergeField or MergeBlock method and work perfectly.
I have no idea why TBS parse "[onload.script=...]" instead of "[onload.subMenu(or subPage);script=...]" until now.
By: Skrol29
Date: 2013-08-29
Time: 00:42

Re: TBS can not always exactly parse my template file

Hi,

The problem is to found why TBS try to merge a field such as [onload.script=...].
Could you send to me a snippet that reproduces the bug you have?
By: Phil
Date: 2013-10-02
Time: 11:08

Re: TBS can not always exactly parse my template file

Hello Skrol29,

This is not TBS's bug. It is my fault.

There are 4 different databases in my project. One of them is user's account database.
It's default collation is Big5. I forgot to convert user's data to UTF-8, when I received them.
After converting them to UTF-8, TBS can correctly parse all my template files now and work perfectly.

Thank you for spending time to test my snippet !!

Regards,
Phil