Template Hook: Can't Work Out What I'm Doing Wrong

James

Well-known member
I think I just need a fresh pair of eyes because I can't find the problem at all, but here goes:

PHP:
public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
{
if ($hookName == 'message_user_info_text')
{
$search = '<h3 class="userText">';
 
 
return str_replace($search, $search . $template->create('UserImages_images', $hookParams)->render(), $contents);
}
}

Why isn't my new template being displayed? The template "UserImages_images" does exist.

EDIT: if I die(str_replace($search, $search . $template->create('UserImages_images', $hookParams)->render(), $contents)), it outputs fine, however when I return it, it doesn't display.
 
No need to return or render. $contents is passed by reference.
$contents = str_replace($search, $search . $template->create('UserImages_images', $hookParams), $contents);
 
Also, you should add to $contents, not replace it (in case other addons use the sage hook location).
Because other developer could already replaced the string you are looking for.
You can just add your stuff before <h3 class="userText"> and use css to make it look as you want.
 
Top Bottom