XF 2.2 Add Forum Category Name to Page Title?

jca

Member
I'm trying to add the Forum (Node) Name to the <title> tag of a page when viewing a thread in a Xenforo forum.

For example, if you are looking at a thread called "Spider-Man No Way Home" in the forum called Movie Discussion, the title of the page would be: "Spider-Man No Way Home Movie Discussion | Site Name" (with subsequent page numbers also included, such as "Spider-Man No Way Home Movie Discussion | Page 2 | Site Name" and so on).

So I believe you would edit the PAGE_CONTAINER template, and edit the <title> tag. I have the Forum Node Name working on it's own, which would look like this:

Code:
<xf:if is="$template == 'thread_view'">{$forum.Node.title}</xf:if>

but I'm having trouble integrating it with my existing template's <title> tag, which is modified from the default:

Code:
<title><xf:if is="$template == 'cinvin_home_view'">{$xf.options.boardTitle} - {$xf.options.boardDescription}<xf:elseif is="$template == 'forum_list'" />Forums | {$xf.options.boardTitle}<xf:else /><xf:title formatter="%s | %s" fallback="{$xf.options.boardTitle}" page="{$pageNumber}" /></xf:if></title>

I seem to be making a mistake trying to integrate the node title as another xf:elseif and also using the xf:title formatter and/or {pageNumber} elements -- I get syntax errors for the "ifs" and so on.

Can anyone help me with this custom <title> tag?

Appreciate any help/info.
 

benFF

Active member
I would just modify the <xf:title> variable before that block and let XF deal with the formatting.

Code:
<xf:if is="$template == 'forum_view'">
    <xf:title><xf:title /> | {$forum.Node.title}</xf:title>
</xf:if>
 
  • Like
Reactions: jca

jca

Member
I would just modify the <xf:title> variable before that block and let XF deal with the formatting.

Hey, thanks for your reply to this (older) thread. You really helped out.

I went off your suggestion and this is the PAGE_CONTAINER template code I came up with to format the page title tag on the thread view page to add the forum category to the page title:

HTML:
<xf:if is="$template == 'cinvin_home_view'"><title>{$xf.options.boardTitle} - {$xf.options.boardDescription}</title>
<xf:elseif is="$template == 'forum_list'" /><title>Forums - {$xf.options.boardTitle}</title>
<xf:elseif is="$template == 'thread_view'" /><title><xf:title><xf:title /> {$forum.Node.title}</xf:title> <xf:title formatter="%s - %s" fallback="{$xf.options.boardTitle}" page="{$pageNumber}" /></title>
<xf:else /><title><xf:title formatter="%s - %s" fallback="{$xf.options.boardTitle}" page="{$pageNumber}" /></title>
</xf:if>

I'm sure there is a better way to format all these xf:if/else statements into a single <title> tag code, but I was having trouble keeping all the different elseif statements straight, so I broke them out separately. If there are any tweaks, mistakes, or redundancies in this template code, please let me know. Thanks.
 

benFF

Active member
Try this:

Code:
<xf:if is="$template == 'cinvin_home_view'">
    <title>{$xf.options.boardTitle} - {$xf.options.boardDescription}</title>
<xf:else />
    <xf:if is="$template == 'forum_list'">
        <xf:title>Forums</xf:title>
    <xf:elseif is="$template == 'thread_view'">
        <xf:title><xf:title /> - {$forum.Node.title}</xf:title>
    </xf:if>

    <title><xf:title formatter="%s - %s" fallback="{$xf.options.boardTitle}" page="{$pageNumber}" /></title>
</xf:if>
 
Top