vBulletin Mods

The Official vBulletin Modifications Site

Why do profile field variables work in some templates but not all?
by john2k
12 Jun 2013 21:24

If I put $post[field2] as the only text/code in the ad_showthread_firstpost template, the value of that field outputs in that location on the page. Basically, it works.

However, if I put that same exact code, $post[field2] , in the ad_header_logo template, I get nothing at all. On the same exact page view, it works in one location but not in the other.

Why does this work in ad_showthread_firstpost but not in ad_header_logo ? It also does not work in the ad_navbar_below template as well.

Is there something that prevents the use of profile field variables in certain templates?

Zachery 12 Jun 2013 21:35

$post is for the postbit. All variables are only available for the templates that within scope.

ad_showthread_firstpost is an ad template, it also happens to be inside of the postbit area, so it should understand to an extent the post var scope. $post is the var that holds all of the data for the postbit of the user who posted.

The ad_header_logo template, isn't inside of the postbit, so it doesn't know what user posted a non existent post.

Depending on what you want to do, I assume for ad_header_logo you want to show this based off of the user who is already viewing the page? Is that correct? Then user $bbuserinfo

$post = postbit* related templates, for the user who actually posted the specific post
$thread/$threadinfo = related to the thread, in the showthread and postbit templates
$bbuserinfo = user who is currently viewing the site.
$vboption = should contain a lot of info, like the admin settings

Those are the biggest ones.

john2k 12 Jun 2013 21:54

Zachery, thanks for all those details.

What I'm trying to do is to turn ads off for paid subscribers if they choose to turn them off. For the ads on/off switch I figured I would use a custom radio button profile field in their usercp.

My ads are well targeted & highly relevant, so many of my subscribers want to be able to keep them turned on, which is why I don't simply surround ad code with a $bbuserinfo usergroup # conditional.

I have the usergroup conditional part of it figured out but am not sure how to take the custom profile field selection & use that as the switch to display or not display the ad code.

Thanks in advance for any additional help, I really appreciate it.

Zachery 12 Jun 2013 22:06

Why? Unless you want to give them a choice.

for the header, it'd be $bbuserinfo['fieldX'] instead of $post

john2k 13 Jun 2013 01:10

Yes, choice is the reason. Some of my subscribers have mentioned they would like to view the site with ads enabled. That is likely due to the high quality & relevancy of the ads.

Your suggestion worked perfectly. For anyone who comes along looking for the same solution in the future, here's what I ended up using:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Basically, that displays the the ad to everyone who is not a member of usergroup #12 and then also displays ads to usergroup 12 members if they either have selected to 'Display All Ads' in their profile or if the value of the profile field is empty. I added in the part to display for the empty variable because even though 'Display All Ads' is selected by default, it does not actually save the value for the variable until the user clicks save on the profile page.

That's pretty much it.

Zachary, thanks for your help! :up:

All times are GMT. The time now is 21:15.

Powered by vBulletin® Version 3.8.14
Copyright © 2021, MH Sub I, LLC dba vBulletin. All Rights Reserved. vBulletin® is a registered trademark of MH Sub I, LLC
Copyright ©2001 - , vbulletin.org. All rights reserved.