XF 2.2 Addon template modification

Anatoliy

Well-known member
So I'm building my first addon that will deal with too long thread titles. So far it can find threads with title length longer than 70 characters and list them.
What I want to do next is to bulk fix them by removing " | Board title" from their titles. So I created a PAGE_CONTAINER template modification that will replace
Code:
<title><xf:title formatter="%s | %s" fallback="{$xf.options.boardTitle}" page="{$pageNumber}" /></title>
with
Code:
<title>
<xf:if is="$noBoardTitle">
<xf:title formatter="%s" fallback="{$xf.options.boardTitle}" page="{$pageNumber}" />
<xf:else />
<xf:title formatter="%s | %s" fallback="{$xf.options.boardTitle}" page="{$pageNumber}" />
</xf:if>
</title>

The question - what would be the best field for storing the "mark" that thread title is too long?
Probably an extra column in xf_threads table, but frankly I'm too afraid to touch xf tables. )
What about a thread custom field? I could create it from ACP so it looks safe. Or it will require an extra query when rendering a thread page?

Will be appreciate for any advice.
Thanks in advance.
 

Brogan

XenForo moderator
Staff member
What version string and ID is in addon.json?

You should be prompted to enter the new version when using bump.
If not, use --force.
 

Anatoliy

Well-known member
ok, now I got it. I just run php cmd.php xf-addon:build-release again and it put Alpha 1 zip next to Alpha. )
so next time after changes I bump version first and then build-release.

Thanks for your help!
 

Anatoliy

Well-known member
So I want to move even further and to teach my template modification to bulk fix too short titles (< 20 characters) by modifying a title from Thread title | Board title to Thread title | Forum Title | Board title. But I have no idea what should go to formatter="%s | %s". Please advise.

Code:
<title>
    <xf:if is="{{strlen($pageTitle ?: '') > 47}}">
        <xf:title formatter="%s" fallback="{$xf.options.boardTitle}" page="{$pageNumber}" />
    <xf:elseif is="{{strlen($pageTitle ?: '') < 20}}" />
        <xf:title formatter="%s | %s" fallback="{$xf.options.boardTitle}" page="{$pageNumber}" />
    <xf:else />
        <xf:title formatter="%s | %s" fallback="{$xf.options.boardTitle}" page="{$pageNumber}" />
    </xf:if>
</title>
 

Anatoliy

Well-known member
I built Alfa 3, that also shows total of threads with titles < 20 characters. 6k+ :eek:
Even with " | My Board Title" they are < 43. And all those SEO gurus say it should be 50-70. So yeah, I want to make that bulk fix badly.

So I tried that dump var, however I didn't find forum title or node title variable, only node_id. But I found breadcrumbs. )
The code
Code:
<xf:elseif is="{{strlen($pageTitle ?: '') < 20}}" />
        <xf:title formatter="%s | {$breadcrumbs.1.value} | %s" fallback="{$xf.options.boardTitle}" page="{$pageNumber}" />
works on a thread page. However on forum pages it shows a title with emptiness in the middle (Forum Title | | Board Title).

How to fix that?
 

XFA

Well-known member
If you are having the thread entity access, then you can use {$thread.Forum.Node.title} to get the forum title.

Forum and Node are entity relations.
 
Top