$context values different when called in a navbar

Started by xTyler, August 01, 2018, 05:12:08 PM

Previous topic - Next topic

xTyler

When I use any of the $context['user'] values in code in my navbar its different than when I call it elsewhere on the forum such as profile.template.

For example, with a mod i have installed, if i call $context['user']['group_image'] in the navbar it simply gives me "image.png" but if i call it elsewhere it gives me <img src="image.png" />"

Any ideas why the variables are different depending on where im calling them?

Thanks, Tyler

Arantor

Because $context refers to the current running state - it's literally different on every single page.

$context['user']['group_image'] isn't something produced by default in the software so that's on the mod author...

xTyler

I see, where would I start to try get them to be the same? It would make things a lot simpler if i could just call $context['user']['group_image'] than <img src="url/group_images/',$context['user']['group_image'],'

Arantor

Given that this is a combination of mods at work, I think you'll need to go through all the code that mentions group_image and tweak it to be consistent.

Can't really be more specific than that, I'm afraid... no idea what custom changes you have.

xTyler

It's added in load.php as this:

'group_image' => !empty($profile['id_group']) && !empty($profile['image']) ? '<img src="' . $settings['images_url'] . '/group_images/' . $profile['image'] . '" alt="" />' : (!empty($profile['id_post_group']) && !empty($profile['image']) ? '<img src="' . $settings['images_url'] . '/group_images/' . $profile['image'] . '" alt="" />' : ''),

Arantor

Which makes it as a full image without anything else - so something else somewhere is overwriting it, which means you'll need to do a search to find it.

xTyler

Only other one I can find is:

'group_image' => !empty($user_settings['id_group']) && !empty($user_settings['image']) ? $user_settings['image'] : (!empty($user_settings['id_post_group']) && !empty($user_settings['image']) ?  $user_settings['image'] : ''),

However, I'm not sure where $user_settings is defined?

Could I just put this into an <img/> tag like how the previous one is declared? I can't see $context['user']['group_image'] called anywhere else in the mod

Arantor

$user_settings is defined in Load.php, in loadUserSettings() - you really shouldn't change it, ever.

Assuming that's being put into $context, I see no reason why you couldn't change it but no idea what else will break.

It's so hard to debug code without seeing ALL of it at once.

xTyler

I understand, I will give it a try and see what happens..

This is the link to the mod if that helps: http://custom.simplemachines.org/mods/index.php?mod=2970

xTyler

Update: It worked, haven't noticed any issues with the rest of the use of the mod (I'm 90% sure $context['user']['group_image'] isn't used elsewhere anyway)

For anyone else wanting to use this mod in the navbar I changed it to:


'group_image' => !empty($user_settings['id_group']) && !empty($user_settings['image']) ? '<img src="' . $settings['images_url'] . '/group_images/' . $user_settings['image'] . '" alt="" />' : (!empty($user_settings['id_post_group']) && !empty($user_settings['image']) ?  '<img src="' . $settings['images_url'] . 'group_images/' . $user_settings['image'] . '" alt="" />' : ''),

Don't forget to add $settings to the imports of  loadUserSettings()

Advertisement: