zero and null in template if statements

Posted by Kuishi 
zero and null in template if statements
October 04, 2011 03:57AM
Hi,

I hope you unterstand my question. My english isnt very well.

The story around my issue:
I have added a custom profile field x_coord with the "enhanced_custom_profiles"-mod. It works well until I enter a zero ( 0 ) in a field. The value is stored in the database correctly. I made a print_r($PHORUM) and there is the 0 too.

I know in PHP the 0 is interpreted as NULL at If-statements. Im using a own template (a copy of emerald with some small changes).

The problem:
I have a loop at the template "cc_groupmod.tpl" and I want to print x_coord if it zero too. I dont want to break the loop and write the whole loop in php. (see example code)

Questions:
1. Is there an option at If-statements on templates to proof if numeric? like the "is_numeric" php-function?
2. can I get a template-var to a php var within the loop to build the if-statement in php?

{LOOP USERS}
<tr>
       <td>
	{IF USERS->x_coord} 
		{USERS->x_coord} 
	{ELSE} 
		none 
	{/IF}
	</td>
</tr>
{/LOOP USERS}

Greetings Kuishi
Re: zero and null in template if statements
October 04, 2011 04:31AM
Seems like the ['TMP'] array contains the loop-data.

This work to me:

                   {LOOP USERS}
                        <tr>
				<td>
						 <?php 
							$x_coord = $PHORUM['TMP']['USERS']['x_coord'];
							$y_coord = $PHORUM['TMP']['USERS']['y_coord'];
							if(is_numeric($x_coord) AND is_numeric($y_coord))
								echo $x_coord . ' / ' . $y_coord;
							else
								echo 'none';
						?>
                              </td>
                        </tr>
                    {/LOOP USERS}

Maybe someone knows a more elegant solution?
Re: zero and null in template if statements
October 04, 2011 06:07AM
yes. thats the variable for the loop elements.
I would break into php too as you have done. Such a "is numeric" function is not available in the simple templating language.


Thomas Seifert
Sorry, only registered users may post in this forum.

Click here to login