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

Display block if variable exists

#1
I have some data I'm passing to the view. There is a part where it is doing a foreach loop to generate some selectunit tags. I only want display the content in the loop if the variable exists.

So in the following I only want this code to be output if $userRoles is set. What are the possible methods of avoiding the undefined variable error when I don't have any $userRoles to loop over?

Code:
<xen:foreach loop="$userRoles" value="$child">
    <xen:selectunit label="{$child.label}" name="options[{$child.name}]">
        <xen:options source="$child.options" />
            <xen:explain>User defined role</xen:explain>
    </xen:selectunit>
</xen:foreach>