$foo|@debug_print_var

{$foo|@debug_print_var}, a {$foo|@print_r} alternative with a better structured output!

If you where like me always using the print_r modifier you will love this!

It basically provides you with the same output but structures it in an easy to read list!

The basic modifier:

{$foo|@debug_print_var}

BUT: this cuts off the longer strings to a max of 40 caracters. (it's the default setting as you can see in the lib\smarty\plugins\modifier.debug_print_var.php file)

Solution: By passing some values with the modifier you can override this behaviour!

{$entry|@debug_print_var:0:40}
  • The 0 is the (default) size of the indent in front of each item
  • The 40 is the (default) max. number of characters for the contents of a single item

ex: By changing the 40 to 400 you can make sure all strings will be fully shown (except if you have something longer than 400... :-p )

{$entry|@debug_print_var:0:400}

Real life examples using CGBlog:

{$entry|@print_r}

Output for this:

stdClass Object 
( 
	[author_id] => 1 
	[author] => admin 
	[authorname] => 
	[id] => 1 
	[title] => News Module Installed 
	[content] => The news module was installed. Exciting. This news article is not using the Summary field and therefore there is no link to read more. But you can click on the news heading to read only this article. 
	[summary] => 
	[postdate] => 2011-09-21 14:05:34 
	[startdate] => 
	[enddate] => 
	[create_date] => 2011-09-21 14:05:34 
	[modified_date] => 2011-09-21 14:05:34 
	[category] => General 
	[fieldsbyname] => Array ( ) 
	[fields] => Array ( ) 
	[file_location] => http://localhost/client/uploads/news/id1 
	[link] => http://localhost/client/index.php?mact=News,cntnt01,detail,0&cntnt01articleid=1&cntnt01origid=34&cntnt01returnid=39 
	[titlelink] => News Module Installed 
	[morelink] => More 
	[moreurl] => http://localhost/client/index.php?mact=News,cntnt01,detail,0&cntnt01articleid=1&cntnt01origid=34&cntnt01returnid=39 
	[printlink] => Print 
	[printurl] => http://localhost/client/index.php?mact=News,cntnt01,print,0&cntnt01articleid=1&cntnt01showtemplate=false&cntnt01returnid=34 
) 1
<pre>{$entry|@debug_print_var:4:400}</pre>

Output for this:

stdClass Object (22)
	->author_id = "1"
	->author = "bu49y8"
	->authorname = " "
	->id = "1"
	->title = "News Module Installed"
	->content = "The news module was installed. Exciting. This news article is not using the Summary field and therefore there is no link to read more. But you can click on the news heading to read only this article."
	->summary = null
	->postdate = "2011-09-21 14:05:34"
	->startdate = null
	->enddate = null
	->create_date = "2011-09-21 14:05:34"
	->modified_date = "2011-09-21 14:05:34"
	->category = "General"
	->fieldsbyname = Array (0)
	->fields = Array (0)
	->file_location = "http://localhost/client/uploads/news/id1"
	->link = "http://localhost/client/index.php?mact=News,cntnt01,detail,0&cntnt01articleid=1&cntnt01origid=34&cntnt01returnid=39"
	->titlelink = "News Module Installed"
	->morelink = "More"
	->moreurl = "http://localhost/client/index.php?mact=News,cntnt01,detail,0&cntnt01articleid=1&cntnt01origid=34&cntnt01returnid=39"
	->printlink = "Print"
	->printurl = "http://localhost/client/index.php?mact=News,cntnt01,print,0&cntnt01articleid=1&cntnt01showtemplate=false&cntnt01returnid=34"

Greetings,
Manuel

Comments