Table of Contents:

Whats it for?

{debug} is one of the most used template functions for template designers.

Its part of the smarty package and can be used to find out what template variables you have available.

A video showing the use of {debug} template call in action

$_conf = configured variables in the system$_user = user looking at the screen$_profile = the profile info of the profile being viewed$_post = stuff coming in from outside the page$_items = all the stuff asked for via jrCore_list

Adding {debug} to a template

When you want to find out what variables you have available to use in a template, {debug} is the function your after.

In this first example, I have created a new template in my active skin and called it junk.tpl for the purpose of learning about {debug}

The text that I wrote in the page will be displayed along with another popup window that shows all of the variables that I can use in the page.

Variables vs Arrays

In the debug dialog there are 2 kinds of structures that we can use. Its very easy to tell which is which just by looking at them.

The first is a variable. A variable has a 1:1 relationship.

When you put the variable name in your template, the value comes out.

In the screenshot above, there is a variable displayed, it is:

{$SCRIPT_NAME}

You can tell its a 1:1 variable because there is only a single value on the right.

On the left is {$SCRIPT_NAME} and on the right is "/modules/jrCore/router.php".

That means if we put {$SCRIPT_NAME} into our template, the value will be displayed.

Check out these screenshots below to see what I mean.

screenshot of junk.tpl with a variable in it

The result of visiting site.com/junk now shows that variable being output.

the output of the variable shows on the page

Arrays

This is different from what would happen if you chose an array variable to put in your page.

Just to illustrate what happens, I'll add

HERE IS THE OUTPUT OF conf {$_conf}

to the template and post a screenshot of what happens.

screenshot of the output of the variable when it contains an array

When the variable contains an array, the only output to the screen will be the word Array.

An array is a set of many values.

If you want to get one of those values out to the screen, you can access it by targeting the value you want by its key.

screenshot highlighting some keys and values in the $_conf array

So if you wanted to output "jr500.iixxii.cc" then you would use this code:

{$_conf.jrCore_system_name}

If you wanted to output: "Asia/Seoul", in the template you would put:

{$_conf.jrCore_system_timezone}

And that way you can access any of the values you're after.

{foreach}

The best place to understand how it all works is by looking at the template files and seeing what the code is doing.

While there you will definitely notice {foreach} because its used everywhere.

Its used in conjunction with arrays to loop over each of the values of the array and output them one by one.

Here's a simple example using the {$_conf} array.

{foreach$_confas$key => $value}
The key is {$key} and the value is {$value}
{/foreach}

That will loop over each of the items in {$_conf} and for every one it finds it will output that sentence, but replace the key and value.

Lets look at a screenshot:

screenshot of $_conf array values output in a foreach loop.

The point

The point is, {debug} lets you know what you have available to you in any template that your working on.

$_conf

$_conf is one of the variables you will always find available to you.

It contains information about the system as a whole. So things like the system name, any module settings, any version info, or limits will likely be found in $_conf

$_user

$_user is another array that will always be available to you. It contains information about the user LOOKING AT THE SCREEN.

Nice big and bold because that's important. It can contain very similar information to $_profile but its very very different.

$_profile

$_profile will be available when you are looking at a profile section of Jamroom. It will contain information about that profile like its name, bio and any other fields that have been added to it via the Form Designer.

an example of a profile field would be $_profile.profile_name and $_profile.profile_url In the case of this profile:

https://www.jamroom.net/michael

The profile_name and profile_url are the same, they are both 'michael'. The difference is that profile_name is intended to be displayed and read, while profile_url is intended to be safe to use in the URL.

$_post

Basically its anything coming in from the browser telling Jamroom what to display.

If you wanted to send some stuff in to the /junk page to tell it what to display, you could do it like this:
site.com/junk/active_tab=music

and you would be have that as a key value pair in $_post.

{$_post.active_tab} would output "music".

$_items

$_items is not available everywhere. You will see it in a lot of locations if you look through the templates, but it will only appear as a result of {jrCore_list} function returning information from the datastore.

If you had:

{jrCore_list module="jrAudio" template="audio-row-template.tpl"}

The put {debug} in audio-row-template.tpl you would see {$_items} in debug.

It would contain not 1 array, but multiple arrays. Each array is a different audio item that has been found and returned.

Most of the {foreach} loops in the templates will be looping over {$_items} like this:

{foreach$_itemsas$key => $item}
........

Then using {$item.audio_title} etc to output the values recorded in the datastore.