Inline Modification Of Helper Data

ibnesayeed

Well-known member
I don't have much expertise in such template languages. Can someone please help me with this.

In the Member Card template it uses a helper function to grab the appropriate CSS string to center/middle align the avatar. Which essentially is a calculated 'left' and 'top' properties depending upon the avatar width and height. But when using it in RTL mode, CSS property 'right' should be used instead of left with the exact same value as of 'left'.

Now I don't want to modify the core files, instead, if I can somehow apply str_replace on the returned string in the template file of the specific style only then I will be good to go.

Here is the related code:

PHP:
<img src="{xen:helper avatar, {$user}, l}" alt="" style="{xen:helper avatarCropCss, $user}{$_avatarStyle}" />

{xen:helper avatarCropCss, $user} portion of the above line returns a string like "left: 48px; top: 42.5px;". Now I want to change that 'left' to 'right'.

Thanks,
 
I'm not aware of any helper or tag which would do string replacement.
You can try overriding the "avatarCropCss" helper itself.

1. Create your own helper which would call the native avatarCropCss helper and do the necessary string replacement before returning the result. Sample untested code:
PHP:
class Sayeed_Template_Helper_Core
{
	public static function helperAvatarCropCss($user, $center = false)
	{
		$css = XenForo_Template_Helper_Core::helperAvatarCropCss($user, $center);

		if (!$css)
		{
			return $css;
		}

		return str_replace('left', 'right', $css);
	}
}

2. Create a new event listener which would replace xenforo's avatarCropCss callback with your helper's callback. You can use my template helper as a reference (the core php code is documented):

» http://xenforo.com/community/threads/gp-template-helper-for-usergroups.6271/
 
Top Bottom