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

XF 1.4 How do I "return" code?

#1
Basically, I'm trying to stop the code from going any further in an if statement.

Stopping the if statement with </xen:if> doesn't seem to work.

I put an if statement inside of an if statement, and if that second if statement that is inside the main if statement is true, I want the code to stop after the <span> tags.

Any way to do this?
 
#4
@Chris D

Here is my code:
Code:
<xen:if is="{$forum.lastPost.date}">
                    <xen:if is="in_array({$forum.node_id}, array(10, 11, 12))">
                    <span class=noMessages muted">Latest message hidden.</span>
                    RETURN
                <span class="lastThreadTitle"><span>{xen:phrase latest}:</span> <a href="{xen:link posts, $forum.lastPost}" title="{$forum.lastPost.title}">{$forum.lastPost.title}</a></span>
                <span class="lastThreadMeta">
                    <span class="lastThreadUser"><xen:if is="{xen:helper isIgnored, $forum.last_post_user_id}">{xen:phrase ignored_member}<xen:else /><xen:username user="$forum.lastPost" /></xen:if>,</span>
                    <xen:datetime time="$forum.lastPost.date" class="muted lastThreadDate" data-latest="{xen:phrase latest}: " />
                </span>
            <xen:else />
                <span class="noMessages muted">({xen:phrase contains_no_messages})</span>
            </xen:if>
If the second if statement (<xen:if is="in_array({$forum.node_id}, array(10, 11, 12))">) is TRUE, I want to stop the code after the <span> right below it, so it doesn't display the "latest" message in the node layout.

If it's not true, and it's not one of those specified node ID's, then it'll continue with the code. What exactly would I put to replace that "RETURN" line I have there as a place holder?
 

Chris D

XenForo developer
Staff member
#5
If I've understood correctly then I think you want something like this:

Code:
<xen:if is="{$forum.lastPost.date}">
    <xen:if is="in_array({$forum.node_id}, array(10, 11, 12))">
        <span class=noMessages muted">Latest message hidden.</span>
    <xen:else />
        <span class="lastThreadTitle"><span>{xen:phrase latest}:</span> <a href="{xen:link posts, $forum.lastPost}" title="{$forum.lastPost.title}">{$forum.lastPost.title}</a></span>
            <span class="lastThreadMeta">
                <span class="lastThreadUser"><xen:if is="{xen:helper isIgnored, $forum.last_post_user_id}">{xen:phrase ignored_member}<xen:else /><xen:username user="$forum.lastPost" /></xen:if>,</span>
                <xen:datetime time="$forum.lastPost.date" class="muted lastThreadDate" data-latest="{xen:phrase latest}: " />
            </span>
    </xen:if>
<xen:else />
        <span class="noMessages muted">({xen:phrase contains_no_messages})</span>
</xen:if>
 
#6
If I've understood correctly then I think you want something like this:

Code:
<xen:if is="{$forum.lastPost.date}">
    <xen:if is="in_array({$forum.node_id}, array(10, 11, 12))">
        <span class=noMessages muted">Latest message hidden.</span>
    <xen:else />
        <span class="lastThreadTitle"><span>{xen:phrase latest}:</span> <a href="{xen:link posts, $forum.lastPost}" title="{$forum.lastPost.title}">{$forum.lastPost.title}</a></span>
            <span class="lastThreadMeta">
                <span class="lastThreadUser"><xen:if is="{xen:helper isIgnored, $forum.last_post_user_id}">{xen:phrase ignored_member}<xen:else /><xen:username user="$forum.lastPost" /></xen:if>,</span>
                <xen:datetime time="$forum.lastPost.date" class="muted lastThreadDate" data-latest="{xen:phrase latest}: " />
            </span>
    </xen:if>
<xen:else />
        <span class="noMessages muted">({xen:phrase contains_no_messages})</span>
</xen:if>
Works perfect!

Thanks very much Chris.