PDA

View Full Version : Use Profile Field Values in Templates


iDCamps
12-20-2010, 09:57 PM
I'm trying to use a custom profile field (specifically, field5) in various places throughout templates. In some places it works just fine (for example, in memberaction_dropdown when it is referenced by postbit). However, other times it doesn't work because the information wasn't passed along to it (for example, in memberaction_dropdown when it is reference by forumbit).

What is the least intrusive way I can get this information passed to the various places I need?

Thanks.

ry215
12-20-2010, 10:56 PM
in template postbit (or postbit_legacy) it called
{vb:raw $post.fieldX}

but in another templates it called
{vb:raw $bbuserinfo.fieldX}

Lynne
12-21-2010, 03:25 AM
It actually depends on if you are trying to get the field of the viewer ($bbuserinfo) or the person who's post/profile/whatever you are viewing ($post, $userinfo, $prepared, etc).

iDCamps
01-04-2011, 02:06 PM
Yeah, that's what I thought.

And that's also the problem: I want to use the value for the person that did the posting in most cases. I also want it to update itself if the person changes that value.

Thus it seems like it isn't available in most places by default. Is there any way that I can drop the in? Could I do it with some form of plugin?

--------------- Added 1294162617 at 1294162617 ---------------

Okay, so I've made a bit of progress.

I've figured out I can make a plugin which will preRegister the values I need. I can then go in to each template and make it use the value.

Now, the tricky part which I could use some guidance on. Obviously each thing needs a different variable converted. Is there any way to get that variable out of the template into my plugin?

For example, forumhome_forumbit_level2_post has a variable forum.lastpostinfo which contains the username. I'd like to get this variable and then either replace it by preRegistering another variable, or even better, just replacing the value in this variable.

I tried creating a new template for this (using vB_Template::create), but it had no registered variables.

Is there a way to do this? The alternative would be to figure out the query for each thing and put in the proper data, but that would be quite a hassle.

Thanks.

Lynne
01-04-2011, 04:57 PM
I'm sorry, but you have totally lost me as far as what you need help with right now.

If you create a new template, then you can register variables in it just before you render it:
$newTemplate = vB_Template::create('someTemplate');
$newTemplate->register('variable1', $somearray);
$newTemplate->register('variable2', $variabletwo);
$newTemplate->render();

iDCamps
01-04-2011, 05:06 PM
I know that much, thanks though.

Let me try to rephrase.

Basically what I want to do is go through and anywhere that a username is shown (in last posts, in post headers, etc), I want to replace that value with a profile field.

I've accomplished this in one place, in memberaction_dropdown. However, it only takes affect when viewing an actual thread, because apparently that's the only place that the field variables are caught (elsewhere it uses the username still because I have it show that using a conditional that checks if the field is set).

So, what I -think- is my problem is I need a way of injecting variables into the various templates I need.

That much I can accomplish using a plugin which is currently hooked to global_start which preRegisters the values I need for each template. I can then go into each template and put those variables into use.

The tricky part is obviously I need to do these changes based on some other value. For example, in some places I'll need to determine what the current value is. This is where I'm stuck... how can I figure out what that value would be.

I know PHP forwards and backwards, but I'm still confused how vB passes variables around between the various template bits, and more importantly, how I can intercept those.

Any help you can provide would be greatly appreciated. If I'm approaching this from the wrong angle, please let me know. The only requirement I'm trying to maintain for this goal is to not have to edit any core code.

Thanks.