Wednesday 26 October 2011

How to waste three hours

Earlier today (aka "yesterday") I wasted a few hour trying to figure out why Smarty hated me. In a project I'm working on, I need a navigation bar that appears on every page, so it's natural to sequester the navigation bar HTML into a sub-template. In the page's toplevel template, I had:


but when I refreshed my page, the navigation area contained, literally, {include file="mainmenu.tpl"}, and not the menu HTML as I expected.

It was just me though: Smarty was singling me out! Its own demo template also includes a sub-template, but that worked just fine.

Round and round I went, trying random settings. Perhaps Smarty wasn't finding its "sysplugins"? Or maybe it had cached Something Bad from an earlier attempt that was wrong for different reasons. Refresh, refresh, fiddle, refresh, curse!

Eventually I got so frustrated I started questioning the fundamentals [1]. Do variable expansions at least work? {$foo} — No! Not working! Just another grinning curly brace pair pseudo-emoticon taunting me in the browser tab!

At least the light went on. Then I discovered what I had forgotten:

$smarty->left_delimiter = '«';
$smarty->right_delimiter = '»';

Guillemet! (I need different delimiters to avoid having to escape CSS declarations sprinkled all over.) Having fixed my Smarty syntax to use those sneaky U+00AB and U+00BB instead of those ubiquitous curly braces, order is restored. Everything works again, and I shall hopefully never again forget that I am using nonstandard delimiters in this project.

[1] Why do I seem always to question my assumptions only when I am at the end of my tether? Recognizing this pattern is as frustrating as knowing that whatever I look for, will only be in the last pocket I search.

1 comment:

  1. Having an E-commerce store that is optimized for the customer requirement is not an easy thing. I definitely do check and correct the E-commerce mistakes and boost my E-commerce conversion rate. Thanks for sharing!
    Smarty Developers
    Hire Dedicated Magento Developer
    Hire Dedicated Web Developers
    Dedicated Wordpress Developer
    Hire Dedicated Php Developer

    ReplyDelete