XF 2.0 Prefix Title from prefix ID; what is contentType?

LPH

Well-known member
I'm trying to tie up loose ends from the past few months of bewilderment. Sorry for all of the "dumb" questions. :notworthy:

@Mike helped on the XenForo 1 version and explained getting the prefix title was an echo of code I'd already done. Now, I'm trying to get the prefix title for the thread in XenForo 2. This is what is currently in the method based on @Chris D reply on dynamic avatars earlier and using the templater which has the fnPrefixTitle.

PHP:
$contentType= '';

$prefixTitle = \XF::app()->templater()->fnPrefixTitle( $contentType, $prefix_id, [], false) ;

var_dump($prefixTitle->getName());

This doesn't give me anything close to a prefix title and I'm thinking this is due to the contentType not being correct or I'm completely on the wrong track.

Can someone please explain what is meant by contentType and what are the options? And if I'm on the right track, then
 
We've designed the prefix system in XF2 to be as content agnostic as possible. There's a lot of code that can be shared and re-used for different content types wanting to implement a prefix system. For example, Resources support prefixes too, so this function can also be used to grab the prefix title for resources.

The differentiator there as you have noted is the content type. For XF Resource Manager prefixes the content type would be resource. For threads, and to answer your question, it is thread.

We recommend that you call templater functions using the fn method in the Templater:
PHP:
$prefixTitle = \XF::app()->templater()->fn('prefix_title', ['thread', 1]);
That will get you the phrase for a thread prefix with a prefix_id of 1.

Note that if you look in the Templater for protected $defaultFunctions you will see a list of function names and the method which they call. Incidentally this is keyed by the names we reference the functions by in templates. You'll see there that prefix_title maps to the fnPrefixTitle method in the templater.
 
The differentiator there as you have noted is the content type. For XF Resource Manager prefixes the content type would be resource. For threads, and to answer your question, it is thread.

Fantastic explanation.

It appears that I was almost there. Well, I was in the room (templater) instead of down a block and lost.

We recommend that you call templater functions using the fn method in the Templater:

Opps. I was off on the fn method but now I have a better feel for contentType. ;)

PHP:
$prefixTitle = \XF::app()->templater()->fn('prefix_title', ['thread', $prefix_id] );

This works and now I'm working to grab the CSS. Thank you!
 
Top Bottom