Search code examples
tinybutstrong

How to get tinybutstrong mergeblock with condition working for empty value


I am using tinybutstrong as a templating engine.

I am trying to get the active link to display in a different color.

The following is my (trimmed down) PHP side:

$links = array (
    '' => 'Home',
    'about' => 'About Us',
    'faq' => 'FAQ',
    'contact' => 'Contact Us',
);
$uri = substr($_SERVER['REQUEST_URI'], 1);
$TBS->MergeBlock('blkLinks', 'array', $links);

Html Template:

<ul>
    <li><a href="/[blkLinks.$;block=li]" style="[onshow;if [onload.uri]=[blkLinks.$]; then 'color:#86AD6D;']">[blkLinks.val;]</a></li>
</ul>

While it generates the html fine and nicely changes the color of the links when that page is currently active, this does not work for the empty (/) link.

How can I fix that?


Solution

  • Simply replace the condition

    [onload.uri]=[blkLinks.$]
    

    with

    '[onload.uri]'='[blkLinks.$]'
    

    The point is that when [onload.uri] is an emprty string, then the expression can be ambiguous. Using the string delimitors, the expression is clear for TBS.