XF 2.3 I want to make a separate Featured content Page node

frm

Well-known member
I am using this code (from the featured content template, stripped down a bit, and in a new template called on the Page node). However, it seems to rely on $features. Is there any other global variable to capture this to display the featured content similarly (to work it into a different layout eventually)?

I still want the What's new -> Featured content to work as is, so I am going with a Page node to accomplish this.

HTML:
<xf:title page="{$page}">{{ phrase('featured_content') }}</xf:title>

<xf:css src="message.less" />

<xf:widgetpos id="featured_content_list_above_features" />

<xf:if is="$features is not empty">
    <div class="block block--articles block--messages block--previews">
        <xf:if contentcheck="true">
            <div class="block-outer">
                <xf:contentcheck>
                    <xf:pagenav link="featured" params="{$filters}"
                        page="{$page}" perpage="{$perPage}" total="{$total}"
                        wrapperclass="block-outer-main" />
                </xf:contentcheck>
            </div>
        </xf:if>

        <div class="block-container">
            <xf:if is="$displayFilters">
                <div class="block-filterBar">
                    <div class="filterBar">
                        <ul class="filterBar-filters">
                            <xf:if is="$filters.content_type">
                                <li>
                                    <a href="{{ link('featured', null, $filters|replace({'content_type': null})) }}"
                                        class="filterBar-filterToggle"
                                        data-xf-init="tooltip" title="{{ phrase('remove_this_filter')|for_attr }}">

                                        <span class="filterBar-filterToggle-label">{{ phrase('content_type:') }}</span>
                                        {{ $xf.app.getContentTypePhrase($filters.content_type) ?: $filters.content_type }}
                                    </a>
                                </li>
                            </xf:if>
                        </ul>

                        <a class="filterBar-menuTrigger" role="button" tabindex="0"
                            data-xf-click="menu" aria-expanded="false" aria-haspopup="true">

                            {{ phrase('filters') }}
                        </a>

                        <div class="menu menu--wide"
                            data-menu="menu" aria-hidden="true"
                            data-href="{{ link('featured/filters', null, $filters) }}"
                            data-load-target=".js-filterMenuBody">

                            <div class="menu-content">
                                <h4 class="menu-header">{{ phrase('show_only:') }}</h4>
                                <div class="js-filterMenuBody">
                                    <div class="menu-row">{{ phrase('loading...') }}</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </xf:if>

            <div class="block-body">
                <xf:foreach loop="$features" value="$feature">
                    {{ $feature.render()|raw }}
                </xf:foreach>
            </div>
        </div>

        <xf:if contentcheck="true">
            <div class="block-outer block-outer--after">
                <xf:contentcheck>
                    <xf:pagenav link="featured" params="{$filters}"
                        page="{$page}" perpage="{$perPage}" total="{$total}"
                        wrapperclass="block-outer-main" />
                </xf:contentcheck>
            </div>
        </xf:if>
    </div>
<xf:else />
    <div class="blockMessage">
        {{ phrase('there_is_not_currently_any_featured_content') }}
    </div>
</xf:if>

<xf:widgetpos id="featured_content_list_below_features" />

<xf:widgetpos id="featured_content_list_sidebar" position="sidebar" />

Otherwise, nothing will be featured, when there is featured content.

1741451986899.webp
 
Last edited:
I am using this code (from the featured content template, stripped down a bit, and in a new template called on the Page node). However, it seems to rely on $features. Is there any other global variable to capture this to display the featured content similarly (to work it into a different layout eventually)?

I still want the What's new -> Featured content to work as is, so I am going with a Page node to accomplish this.

HTML:
<xf:title page="{$page}">{{ phrase('featured_content') }}</xf:title>

<xf:css src="message.less" />

<xf:widgetpos id="featured_content_list_above_features" />

<xf:if is="$features is not empty">
    <div class="block block--articles block--messages block--previews">
        <xf:if contentcheck="true">
            <div class="block-outer">
                <xf:contentcheck>
                    <xf:pagenav link="featured" params="{$filters}"
                        page="{$page}" perpage="{$perPage}" total="{$total}"
                        wrapperclass="block-outer-main" />
                </xf:contentcheck>
            </div>
        </xf:if>

        <div class="block-container">
            <xf:if is="$displayFilters">
                <div class="block-filterBar">
                    <div class="filterBar">
                        <ul class="filterBar-filters">
                            <xf:if is="$filters.content_type">
                                <li>
                                    <a href="{{ link('featured', null, $filters|replace({'content_type': null})) }}"
                                        class="filterBar-filterToggle"
                                        data-xf-init="tooltip" title="{{ phrase('remove_this_filter')|for_attr }}">

                                        <span class="filterBar-filterToggle-label">{{ phrase('content_type:') }}</span>
                                        {{ $xf.app.getContentTypePhrase($filters.content_type) ?: $filters.content_type }}
                                    </a>
                                </li>
                            </xf:if>
                        </ul>

                        <a class="filterBar-menuTrigger" role="button" tabindex="0"
                            data-xf-click="menu" aria-expanded="false" aria-haspopup="true">

                            {{ phrase('filters') }}
                        </a>

                        <div class="menu menu--wide"
                            data-menu="menu" aria-hidden="true"
                            data-href="{{ link('featured/filters', null, $filters) }}"
                            data-load-target=".js-filterMenuBody">

                            <div class="menu-content">
                                <h4 class="menu-header">{{ phrase('show_only:') }}</h4>
                                <div class="js-filterMenuBody">
                                    <div class="menu-row">{{ phrase('loading...') }}</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </xf:if>

            <div class="block-body">
                <xf:foreach loop="$features" value="$feature">
                    {{ $feature.render()|raw }}
                </xf:foreach>
            </div>
        </div>

        <xf:if contentcheck="true">
            <div class="block-outer block-outer--after">
                <xf:contentcheck>
                    <xf:pagenav link="featured" params="{$filters}"
                        page="{$page}" perpage="{$perPage}" total="{$total}"
                        wrapperclass="block-outer-main" />
                </xf:contentcheck>
            </div>
        </xf:if>
    </div>
<xf:else />
    <div class="blockMessage">
        {{ phrase('there_is_not_currently_any_featured_content') }}
    </div>
</xf:if>

<xf:widgetpos id="featured_content_list_below_features" />

<xf:widgetpos id="featured_content_list_sidebar" position="sidebar" />

Otherwise, nothing will be featured, when there is featured content.

View attachment 319893
This might help: https://xenforo.com/docs/dev/lets-build-an-add-on/#create-the-add-on
 
Templates don't work stand-alone, they're backed by a controller (\XF\Pub\Controller\FeaturedContentController::actionIndex). You could create a widget and embed it onto the page via <xf:widget .../>, but if you want to do anything more complicated then it won't be possible with templates alone.
 
Templates don't work stand-alone, they're backed by a controller (\XF\Pub\Controller\FeaturedContentController::actionIndex). You could create a widget and embed it onto the page via <xf:widget .../>, but if you want to do anything more complicated then it won't be possible with templates alone.
Attempting an add on would be more beneficial then, as the widget would be very limiting. Just need to figure out what $features is grabbing to pass along, and we'll be all set.
After Jeremy's response, it looks like I have to. I figured there could be a hidden $xf.thread.featured_threads variable (or a global one) that I was overlooking (expanding all the menus of a dump()) that passed the same threads over to work in sync with the template's loop. But it doesn't appear to be the case.
 
It would work, but I'd need to heavily modify forum_view to display them how I'd like, making upgrading more difficult with memergers.
You could use a dedicated template without modifying forum_view too much, eg. just wrap the whole template in a conditional to use the original or include your version.
 
  • Like
Reactions: frm
You could use a dedicated template without modifying forum_view too much, eg. just wrap the whole template in a conditional to use the original or include your version.
That would be the way that I'd do it (conditional if and call the new template). But, even then, forgetting it's there, I'd need to peer closer at merging templates on upgrade whilst an add on won't have that problem.

Seems like it would be best as an add on to call the template, though, and perhaps, even more variables that could be passed along in that (such as the number of participants in the featured thread).
 
Back
Top Bottom