• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

xen:if condition NOT

#1
here's the setup:
I'm doing this (which works):
Code:
<xen:foreach loop="{$user.identities}" key="$service1" value="$account1">
<xen:if is="{$service1} == 'Steam'">
        <div class="steamprofile" title="{$account1}"></div>
</xen:if>
the result is, if the identity "steam" exists, then a div is printed; if it doesn't exist, nothing happens

what I would like to do is
Code:
if (!in_array("Steam', $user.identities) {
 echo "What the? no steam?";
}
obviously this is not xen templating :)
can this be done ?

in plain english:
if the key "Steam" does not exist, then print some plain text.
 

Shadab

Well-known member
#2
Looking at the code for Template Compiler, it does support some native php functions:
  • is_array, is_object, is_string, isset, empty, array_key_exists, count, in_array, array_search
  • preg_match, preg_match_all, strpos, stripos, strlen, ceil, floor, round, max, min, mt_rand, rand

So you can use this in your template:
HTML:
<xen:if is="!in_array('Steam', {$user.identities})">
	Test
</xen:if>
 

Shadab

Well-known member
#4
While saving the template?
I just tried and it saved without a hitch.

You'll definitely get an error, though, if "$user.identities" is not an array.
Code:
in_array() expects parameter 2 to be array, null given
 
#6
Hi Shadab or anyone else.

This seems to have stopped working with an update somewhere (could be a theme update as well? theme: Whisper)
here's the code I'm using in message_user)info
Code:
	<xen:hook name="message_user_identities" params="{xen:array 'user={$user}'}">
	 <xen:foreach loop="{$user.identities}" key="$service1" value="$account1">
	 <xen:if is="{$service1} == 'Steam'">
		<div class="steamprofile" title="{$account1}"></div>
	 </xen:if>
	 </xen:foreach>
	 <xen:if is="!in_array('Steam', {$user.identities})">
		<div class="steamprofileNOT" title="No Steam"> &nbsp; <a href="account/contact-details">NO SteamID entered</a></div>
	 </xen:if>
	</xen:hook>
the first section works well, bit it seems the !in_array has stopped working.
example: http://www.fps.net.nz/community/threads/got-my-first-unusual-for-pyro.21/
Can anyone help?
Thanks in advance.
 

Shadab

Well-known member
#7
You can check the "Outdated Templates" section in Admin Panel, for a list of templates that need to be reverted & reedited.

Could you place
Code:
{xen:helper dump, $user.identities}
somewhere in that template, and see what the output is?
 
#8
output of dump:
Code:
array(4) {
  ["facebook"] => string(14) "TerminalAddict"
  ["gtalk"] => string(14) "TerminalAddict"
  ["msn"] => string(23) "terminapaul@hotmail.com"
  ["Steam"] => string(18) "STEAM_0:0:25947321"
}
looks good :)

outdated templates (which I don't fully understand?)

Default Style
1. login_bar_form Custom Version: 1.0.0 Beta 5, Master Version: 1.0.0 Beta 6
2. forum_list Custom Version: 1.0.0 Beta 5, Master Version: 1.0.0 Release Candidate 1
3. PAGE_CONTAINER Custom Version: 1.0.0 Beta 5, Master Version: 1.0.0 Beta 6
Whisper
1. GP_Steam.css Custom Version: , Master Version: 1.0.1

btw: I just reverted all those templates, and re-applied edits to forum_list and login_bar_form
 
#9
fixed .. bit of a duh! moment for me :)

I used array_key_exists instead
Code:
	 <xen:if is="!array_key_exists('Steam', {$user.identities})">
		<div class="steamprofileNOT" title="No Steam"> &nbsp; <a href="account/contact-details">NO SteamID entered</a></div>
	 </xen:if>