PDA

View Full Version : Conditional in <phrase>


ringleader
08-25-2008, 08:42 PM
I'm trying to replace the username across the forum with a Userfield of my own.

However, I'm running into difficulty with the double quotes (I think).

I'm trying to replace
$bbuserinfo[username]

with

<if condition="$bbuserinfo[fieldX]">$bbuserinfo[fieldX]<else />$bbuserinfo[username]</if>

However, many templates use $bbuserinfo[username] in phrases like:
<phrase 1="$bbuserinfo[username]"></phrase>

Desired result:
<phrase 1="$bbuserinfo[username]"></phrase> when $bbuserinfo[fieldX] exists, but
<phrase 1="$bbuserinfo[fieldX]"></phrase> when $bbuserinfo[fieldX] exists.

How would I go about replacing my conditional in there, or is it possible at all?

Opserty
08-26-2008, 08:09 AM
What have you actually tried in the code then? (What was the output/error if it never worked).

Marco van Herwaarden
08-26-2008, 09:07 AM
Why not use:

<if condition="$bbuserinfo[fieldX]">
<phrase 1="$bbuserinfo[fieldX]"></phrase>
<else />
<phrase 1="$bbuserinfo[username]"></phrase>
</if>

ringleader
08-26-2008, 10:04 AM
What have you actually tried in the code then? (What was the output/error if it never worked).

I should've included that alright, but it was the usual 'unescaped double quote' type error.

Still, the basis of it was that construct_phrase() couldn't handle a conditional - it needed to be interpreted before it went into <phrase 1=""> etc.

Why not use:

<if condition="$bbuserinfo[fieldX]">
<phrase 1="$bbuserinfo[fieldX]"></phrase>
<else />
<phrase 1="$bbuserinfo[username]"></phrase>
</if>

That's the stuff!
I knew there was a way to interpret my phrase or the other phrase in a conditional :D

I'll buy you a pint next time you're in Ireland, guaranteed* ;)

*not a guarantee