User Tools

Site Tools


Sidebar

designers:debug_smarty_tag

How To Use The Built-in Smarty Tag {debug}

We get questions all the time from those that wish to make changes to system/module/addon templates within the software. One of those questions is "how do we know what tags/variables are available to a template?". The answer is that you can easily find out by inserting the built-in Smarty tag {debug} within that template. You only need to put that tag anywhere within the template to trigger a popup that will display all variables assigned within the smarty workspace up to that point. This tag dumps the debug console from within the Smarty engine to the popup that appears. Note that this only shows the assigned variables that we actually assign with the base php code and available within that template used for that page. It does not display any smarty variables created/assigned within that template using the "smarty assign" tag. It is best to only use this when you have caching turned off within your Geo software or you could see a cached copy of those variables. It is best to put this tag at the end of the template as to also see the variable assigned within that template. Simply inset this:

{debug}

Suggestions:

  • This only displays the popup at runtime. So insert the tag and then view the page that uses that template on the client side. If inserted properly and in the relevant template you will see the popup.
  • All who visit a page with this tag in the template will see the popup. So it's only suggested to use this in a development installation not for public view. If you need to do this on a live site insert the tag, go to the page on the client side to "trip" the tag, immediately return to the admin tool to remove the {debug} tag from the template and save the change. Note there are extra steps described in the next section that could show the debug console only to a specific ip address.
  • You may consider only doing this on a template you as the admin see. You can force a specific template set to load for you using suggestions made in the template set loading tutorial
  • As this displays all smarty variables within the "smarty workspace" we suggest you put this at the end of the last template used within that specific page load. As this displays all up to the point of the debug tag placing at the end of the last template makes all within the smarty workspace display and not just those included within the template up to the point of the tag if placed in the middle. If this tag is placed in the middle the a template included within the middle of the page the smarty console output starts there and can mess with the display of the page. Placing at the end of the last template will ensure that ALL smarty variables used in that smarty work environment will be displayed and there will be less impact on the display of the page.

Tip: Only load debug for You (IP Based)

Here is a handy tip, submitted by an active 3rd party developer in the user forums, that allows the {debug} to only work when the page is viewed by yourself, based on the IP address. First you need to know what your IP address is, if you are not sure you can always find out on a website like whatismyip.com. Then insert the following in your template:

{if $smarty.server.REMOTE_ADDR == 'YOUR_IP_HERE'}
	{debug}
	{* other debugging code goes here *}
{/if} 

You need to replace YOUR_IP_HERE with your IP address. Note that even with this tip, we recommend to only use {debug} on a temporary basis, it is not a good idea to keep the {debug} tag in your templates permanently if you no longer need it.

designers/debug_smarty_tag.txt · Last modified: 2016/07/27 21:31 by geojames