William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

Smarty Templates: {debug}

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%; */
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: