XF 2.0 pageaction change in forum_view

Sperber

Well-known member
Hi,

may be someone could help me over the street, please, since I´m just not getting it. I´m trying to reroute the create thread button in particular forums (via forum_view) with
Code:
<xf:pageaction if="$forum.canCreateThread()">
    <xf:if is="{$forum.node_id} == 56">
            <xf:button href="{{ link('resources/categories/add', $category) }}" class="button--cta" icon="write">{{ phrase('xfrm_add_resource') }}       
            </xf:button>
    <xf:elseif />
    <xf:if is="{$forum.node_id} == 117">
            <xf:button href="{{ link('showcase/categories/add', $category) }}" class="button--cta" icon="write">{{ phrase('xa_sc_add_item') }}
            </xf:button>
    <xf:else />
            <xf:button href="{{ link('forums/post-thread', $forum) }}" class="button--cta uix_quickPost--button" icon="write">{{ phrase('post_thread') }}
            </xf:button>
    </xf:if>
</xf:pageaction>

but if I put this in the template the
Code:
</xf:pageaction>
becomes highlighted in red as an error. Saving produces the error that an "if" is expected instead.

What the heck am I doing wrong..? :unsure:
(Yes, of course it says I am missing an "if" statement - but I don´t understand why there and for what reason. And no, the answer is not: drink more coffee ;) )
 
Last edited:
If I had to guess, your control flow is:

if node_id == 56
do work
else if node_id == 117
do other work
else
do default work
end if

If that's the case, your need to specify your second condition in the elseif, not in it's own if statement, like so:

Code:
<xf:pageaction if="$forum.canCreateThread()">
    <xf:if is="{$forum.node_id} == 56">
            <xf:button href="{{ link('resources/categories/add', $category) }}" class="button--cta" icon="write">{{ phrase('xfrm_add_resource') }}       
            </xf:button>
    <xf:elseif is="{$forum.node_id} == 117">
            <xf:button href="{{ link('showcase/categories/add', $category) }}" class="button--cta" icon="write">{{ phrase('xa_sc_add_item') }}
            </xf:button>
    <xf:else />
            <xf:button href="{{ link('forums/post-thread', $forum) }}" class="button--cta uix_quickPost--button" icon="write">{{ phrase('post_thread') }}
            </xf:button>
    </xf:if>
</xf:pageaction>
 
I´ve used this in the first place and it turned out that both lines
Code:
    </xf:if>
</xf:pageaction>
become highlighted as errors. That´s why I wanted to give that splitted elseif a try and it´s a bit weired that this shows only one line as an error.

@Brogan , are you there - any idea?
 
Ah, I found it. The elseif needs a /> in it, since it has no closing tag. So, instead of
<xf:elseif is="{$forum.node_id} == 117">
you should have
<xf:elseif is="{$forum.node_id} == 117" />

In the end, this is what it looks like:

Code:
<xf:pageaction if="$forum.canCreateThread()">
    <xf:if is="{$forum.node_id} == 56">
            <xf:button href="{{ link('resources/categories/add', $category) }}" class="button--cta" icon="write">{{ phrase('xfrm_add_resource') }}       
            </xf:button>
    <xf:elseif is="{$forum.node_id} == 117" />
            <xf:button href="{{ link('showcase/categories/add', $category) }}" class="button--cta" icon="write">{{ phrase('xa_sc_add_item') }}
            </xf:button>
    <xf:else />
            <xf:button href="{{ link('forums/post-thread', $forum) }}" class="button--cta uix_quickPost--button" icon="write">{{ phrase('post_thread') }}
            </xf:button>
    </xf:if>
</xf:pageaction>
 
Top Bottom