• Blogs (9)
    • 📱 236 - 992 - 3846

      đź“§ jxjwilliam@gmail.com

    • Version: ‍🚀 1.1.0
  • Smarty Templates: {debug}

    Blogs20112011-11-13


    Smarty Templates: {debug}

    Smarty has a brilliant built-in function: {debug}. Normally at the top of smarty template, call this built-in function to make the page in debug mode:

    {$debug}

    After this set, all the currently available variables within the scope of a template are displayed in a new window. The {debug} plus FF’s Firebug, Web developers tools make the developing more efficient and easily.

    I list the following slight changes of the {debug} to make it more readable for me. All these changes can be done by directly modifying Smarty source codes.

    1. change default print variable length from 40 to 120

    In Linux where the Smary resides, directly change Smarty lib file:

    ~/Smarty-3.0.4/libs/plugins/$ vi modifier.debug_print_var.php
    // change $length=40 to 80:
    function smarty_modifier_debug_print_var($var,$depth=0,$length=80)

    This way, if out long variables, such as array, array of array etc, the display shows at max 80 chars instead of original 40 chars.

    2. make debug window more suitable

    I customized the {debug} window to show more comfortable:

    • make Window’s width more wider, from 680 to 1080px
    • ignore the td width, this keeps the display more reasonable.

    To do this, directly edit Smarty lib file: vi ~/Smarty-3.0.4/libs/debug.tpl:

    _smarty_console = window.open("",
     title.value,"width=1080,height=600,resizable,scrollbars=yes");
    // and comment the width of th,td tags:
    th, td{
    /* width: 50%; */
    }