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

XF 1.5 Inline Xen:elseif in a template

abdfahim

Active member
#1
Is it okay to use a long "xen:elseif" chain in a template like below?

Code:
class = {xen:if '{$user.customFields.my_id1} == "A"', 'class1', {xen:if '{$user.customFields.my_id2} == "A"', 'class2', {xen:if '{$user.customFields.my_id3} == "A"', 'class3', {xen:if '{$user.customFields.my_id4} == "A"', 'class4'}}}}
 

Yugensoft

Active member
#2
You could do it, but it might be better to use a helper function if you have that many cases.

Then you would just do something like class='{xen:helper customfieldsclass, $user.customFields}', and write a helper function to return the desired class based on the contents of customFields.