View Full Version : Add username to widget title
AcheronAI
09-23-2012, 12:09 PM
I am trying to get a widget to where the title changes per user, I have yet to find the right place to do this.
Any help would be very much appreciated.
You could find the template associated with the widget and put a variable in for the title (the CMS templates are in the vBulletin CMS templates group). If you can't guess the template name, you can temporarily turn on "Add Template Name in HTML Comments" (in the General Settings section) and view the html source of the page, then find the widget title html and look for the comment telling you which template it in.
AcheronAI
09-23-2012, 12:43 PM
I tried putting welcome $vbulletin->userinfo[username] and it just shows exactly what I typed as a title.
I am using a php output widget, and yet to find a way to get this done how I wish lol
If you're putting it in the template, then you'd need to use {vb:raw bbuserinfo.username}. Also, if it's a php custom widget then you can set which template you want to use as a "wrapper", and if you use the default template and make changes to it, it will change all php custom widgets (assuming you have more than one).
AcheronAI
09-23-2012, 01:42 PM
Actually I was just trying to add to the title to be displayed by the widget to fit who is viewing. I figured it out with a bit of work.
Thanks for the help though :)
Oh, I see (I think) - you managed to change the title variable in the php code? You should post what you did in case someone else wants to know.
AcheronAI
09-23-2012, 02:07 PM
Well this is not pretty , fair warning lol
First I made a new PHP Direct Execution widget and for the title put{vartitle} or what ever you wish, it just has to match up in this next part.
Create a new plugin with the hook location
vbcms_process_widget_complete
Use the following php code
global $vbulletin;
$newtitle = "Your new title";
$widget_views[$widgetid] = str_replace("{vartitle}", $newtitle ,$widget_views[$widgetid]);
It is so simple once I finally pinned it down, but finding it was not fun :)
But now you can add any code you wish before hand and have $newtitle reflect what you wish to show in the php widget title area.
That looks good to me. When you're modding stuff, anything goes as long as it works, IMHO. And that solution saves having to mess with the templates.
AcheronAI
09-23-2012, 02:35 PM
Ya the only thing I did with templates was get rid of the ugly php icon. I tested this with putting an image in the title, and it looked nice.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.