vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=242)
-   -   [HOW-TO vB4] Create a Widget using Plugins and Templates (https://vborg.vbsupport.ru/showthread.php?t=236245)

Mythotical 02-17-2010 10:00 PM

[HOW-TO vB4] Create a Widget using Plugins and Templates
 
In this tutorial I am hoping to enlighten many in wondering how to do their own custom widget without confusion.

I came across someone needing help with a widget issue, they could not get javascript to work nor PHP in the widget so I dug right in, keep in mind this is my first widget so I was doing this blindly, but upon digging in I realized it was easy once I learned what each portion of the system did, only took about 15 or 20 mins to figure it out. So I feel anyone can learn to do a widget faster than their own modification.

Lets begin, keep in mind that this is explained on how I did it and if you have questions with any aspect explained or not then just ask, I will gladly answer.

Step 1. - Widget Creation

With this step you want to create your widget first, I prefered to create the widget first as it seemed logical but you can rearrange the steps once you are used to the system.

Go to: AdminCP > vBulletin CMS > Widgets

https://vborg.vbsupport.ru/external/2010/02/18.png

Step 1a. - Widget Creation - Details

Click Create Widget at the bottom of this new page.

https://vborg.vbsupport.ru/external/2010/02/19.png

We now have a new page with boxes for: Widget Type, Title, and Description. Lets get the boxes filled in.

Widget Type: Static HTML
Title: My Widget (Name your widget whatever you would like)
Description: Make the description explanatory of what this widget does.

https://vborg.vbsupport.ru/external/2010/02/20.png

Click Save to create your new widget.

Step 2. - Widget Location

You'll need to go to AdminCP > vBulletin CMS > Layout Manager

The new page will load, on this page you have a list of layouts you have created or default layout. Find the layout you want to have this widget appear on and click GO next to the dropdown that is in line with your layout you have chosen, make sure Edit is selected from the dropdown.

https://vborg.vbsupport.ru/external/2010/02/21.png

Step 2a. - Widget Select and Add

From the box to the left, you will see all available widgets that have been created. Select your newly created Widget and click the > that is the right of that box.

https://vborg.vbsupport.ru/external/2010/02/22.png

Step 2b. - Move Widget

Once you have added the widget, a new box will appear with your Widget's title, mine is titled My Widget. You can click the darker bar with your widget title in it to move it to which ever column you choose.

https://vborg.vbsupport.ru/external/2010/02/23.png

Then click Save at the bottom to save the location.

Step 3. - Configure Widget

Head back to your left menu and click on Widgets.

When the page loads, find your widget and at the far right click Configure as the screenshot shows below.

https://vborg.vbsupport.ru/external/2010/02/24.png

Step 3a. - Configure Widget Page

A box will popup and turn the background black. In this new window or box do the following.

Enter Static HTML: Empty the box of everything
Template Name: Enter the name of your template you plan to create for use with this widget.

https://vborg.vbsupport.ru/external/2010/02/25.png

Step 4. - Add Widget Template

Go to: AdminCP > Styles & Templates > Style Manager

https://vborg.vbsupport.ru/external/2010/02/26.png

On that page, find the style you want this widget to appear with, then from the drop down to the far right choose Add New Template.

https://vborg.vbsupport.ru/external/2010/02/27.png

Step 4a. - Template Information

When the Add New Template page loads fill the boxes as listed below.

Title: Enter the name of your template, it is the same name that you entered when configuring your widget in Step 3.
Template: Enter the following html into this area.
HTML Code:

<div class="cms_widget">
    <div class="block">
        <div class="cms_widget_header">
        <h3>{vb:raw widget_title}</h3>
        </div>
        <div class="cms_widget_content">
        Testing my widget, this is my username: {vb:raw myusername}
        </div>
    </div>
</div>

Click save once you have entered the template info.

https://vborg.vbsupport.ru/external/2010/02/28.png

Step 5. - Plugin Creation

Go to: AdminCP > Products & Plugins > Plugin Manager (You can create yourself a new product but if you are new to any type of vB modifying then I suggest you don't attempt to create a product)

https://vborg.vbsupport.ru/external/2010/02/29.png

On the new page, scroll to the bottom and click on Add New Plugin

https://vborg.vbsupport.ru/external/2010/02/30.png

Step 5a. - Plugin Info (Keep in mind this is for testing purposes)

On this page, fill in the boxes as provided below.

Product: Choose vBulletin CMS (If you created a product, choose it from the drop down)
Hook Location: global_start (Choose the plugin that fits best into where you want this to be shown, global_start is the best option for now)
Title: Give descriptive title
Execution Order: Leave this field alone
Plugin PHP Code:
PHP Code:

$myusername =  $vbulletin->userinfo['username'];

vB_Template::preRegister('vbcms_widget_mywidget',array('myusername'  => $myusername)); 

Plugin is Active: Set this to YES

Then click save and done

https://vborg.vbsupport.ru/external/2010/02/31.png

You are done. Now load your page and view your widget in action.

https://vborg.vbsupport.ru/external/2010/02/32.png

zanthor 02-25-2010 03:08 PM

Unless I am completely out of my mind the hook global_start isn't nearly as global as one would hope... When I changed this to init_startup I got this working, global_start would fire on forums but not CMS...

Mythotical 02-25-2010 05:00 PM

Zanthor, you are correct but what I used was an example. Nothing more. I left this article open for others to play around with it and try different things. The widget that I tested showed on the forumhome not the CMS.

Joseph Witchard 02-28-2010 01:31 AM

How exactly do you know which hook to choose? I'm guessing you can probably see a complete list of all the hooks from that dropdown menu, but how are you supposed to know what each of them does and if it should be used for your particular mod?

Mythotical 02-28-2010 01:46 AM

Well lets say you want to display info only when visiting a forum then it would be a forumdisplay, forumhome, etc type of hook. Global site would be init_start or global_start. Profile would be anything that has profile at the beginning. Basically each hook starts with the name of the part of the site it deals with.

Joseph Witchard 02-28-2010 02:11 AM

So if several hooks started with the same thing, you would need to give your best guess as to which one would be the right one of your mod?

Mythotical 02-28-2010 02:21 AM

Most have a start, end, complete, etc. Just depends on if you feel it will be best suited at start or complete. Usually you can open the file of the page your looking for, then find the hook of where it would fit into place.

heywho 03-01-2010 07:57 PM

Hi, this is my first try at widget creation, and I'm a vB noob.... so this is pretty much over my head

Would like to create a widget using script

Code:

<script src="http://www.gmodules.com/ig/ifr?url=http://static.die.net/earth/gadget.xml&amp;up_clouds=1&amp;up_proj=mercator&amp;synd=open&amp;w=240&amp;h=137&amp;title=World+Sunlight+Map&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js"></script>
you can see the widget here :

Any help would be greatly appreciated... Thanks

Mythotical 03-05-2010 04:02 AM

heywho: You would do it just the same way. I haven't tested it but the script code would go in the same place that html code would go in the template. If you tested it, I will attempt to figure it out once I've had some sleep.

Sorry for the delay, somehow the email regarding a new reply to this thread snuck by me.

Joseph Witchard 03-07-2010 02:23 AM

Quote:

Originally Posted by Steve M (Post 1993376)
Most have a start, end, complete, etc. Just depends on if you feel it will be best suited at start or complete. Usually you can open the file of the page your looking for, then find the hook of where it would fit into place.

How do you know which page the hook is located in?

Mythotical 03-07-2010 03:01 PM

If you want it on the profile only then fine a hook that begins with profile, you can open the .php file for that page then just find the hook that is closest to what you want. You can search the file for hook to find them.

Joseph Witchard 03-08-2010 02:24 AM

Okay, this question might be a little late, but for the sake of understanding, I'm going to ask it anyway: what does a widget exactly do? I was a little confused by your end example on your first post.

heywho 03-10-2010 02:19 AM

Quote:

Originally Posted by Steve M (Post 1997485)
heywho: You would do it just the same way. I haven't tested it but the script code would go in the same place that html code would go in the template. If you tested it, I will attempt to figure it out once I've had some sleep.

Sorry for the delay, somehow the email regarding a new reply to this thread snuck by me.

Hey, TY for info, I'll give it a try tonight.. sometimes, I forget I asked a questoin if I don't subscribe -- appretiate

Mythotical 03-11-2010 01:46 AM

Quote:

Originally Posted by Joseph Witchard (Post 1999554)
Okay, this question might be a little late, but for the sake of understanding, I'm going to ask it anyway: what does a widget exactly do? I was a little confused by your end example on your first post.

A widget is simply an info box in a sidebar that you can have appear on your forum or CMS page.

heywho: No problem, good luck

Joseph Witchard 03-11-2010 02:10 AM

Must you put it in a sidebar? Could you put it in the header, for example?

Mythotical 03-11-2010 02:21 AM

Quote:

Originally Posted by Joseph Witchard (Post 2001278)
Must you put it in a sidebar? Could you put it in the header, for example?

Nope, widgets are meant for the columsn in the CMS or a sidebar on your forum only.

Joseph Witchard 03-11-2010 02:59 AM

All right. Thanks:)

Crimm 05-18-2010 02:52 AM

I just wanted to tell you that as I get my mods updated ... this article has been wonderful.

BRAVO

Thank you!

ragtek 05-18-2010 12:27 PM

If you would use the php execution widget instead of the html widget, you wouldn't need to deal with variables and the templatse in global plugins!!!

Specialy if you have db queries or other stuff it isn't neccessery to run it global if you don't need it...

clubvr4 08-17-2010 06:32 PM

I can't get this working on 4.0.6 - repeated process twice, anything changed?

I'm very keen to get this up and running, modifying widgets via templates ftw.

ahmedipa 04-29-2011 09:35 AM

nice one I will try to do it next time

TalkVirginia 04-30-2011 11:58 AM

I was able to get this to work on the CMS using the process_template_complete hook location.

TheMac 09-03-2011 10:01 AM

Hello! I want to show the content of a Widget only to guests, do you know how to it?
I have tried this also with the default info and nothing :(

Mythotical 09-23-2011 03:42 AM

Quote:

Originally Posted by TheMac (Post 2241468)
Hello! I want to show the content of a Widget only to guests, do you know how to it?
I have tried this also with the default info and nothing :(

That would require an if condition to show only to your guest usergroup.

djrockinsteve 11-21-2011 12:17 AM

Thank you very much for detailing the process. The vBulletin tutorial omits a few details probably due to software updates.

I had to select forum complete to not get html code across the top of the page or to change the appearance of the home page, but I cannot find it anywhere on the entire forum. Running latest version.

FYI it is a weather widget showing local weather.

Any thoughts or suggestions.

Thanks again

rbc1225 02-28-2012 03:01 AM

This article helped a great deal in some of the very basic controls of the template creation and such.

thanks

maryx 04-24-2012 06:22 PM

I already have the widget for most recent blogs.

Can someone help me create a widget that would pull the posts from one particular blog and put them on the Content page?

Thanks!

Badshah93 06-28-2012 01:36 PM

if someone wants to create Widget as per this article

Change the hook:
global_start to vbcms_process_widget_complete

and when you are creating new widget (Static Html)
do enter something in that box, else widget won't display.

BirdOPrey5 06-28-2012 06:37 PM

Big thanks Badshan93. I couldn't figure out why the template wasn't displaying.

Mythotical 07-14-2012 05:53 AM

I will be redoing this article as it seems things have changed.

Draffi 08-07-2012 07:05 PM

Thank you for this.

With this one, it was possible for me to show the [DBTECH]Shoutbox in the CMS as a widget !!!

BUT i have no right colum - it is not showing....

I think, this part what i`m using in the Plugin-Step is wrong, can somebody help me?

Code:

vB_Template:('vbcms_widget_MyWidget');
or maybe my self-created template has not enough code inside...

Code:

<div>{vb:raw show.vbshout_instance1}</div>
Thank you in advance!

Amenadiel 10-01-2014 07:17 PM

Quote:

Originally Posted by Badshah93 (Post 2343585)
if someone wants to create Widget as per this article

Change the hook:
global_start to vbcms_process_widget_complete

and when you are creating new widget (Static Html)
do enter something in that box, else widget won't display.

I found out that the vbcms_process_widget_complete hook works, but it seems to be inside of a function, so you have to prepend

PHP Code:

global $vbulletin

for the plugin to work.

Scalemotorcars 02-26-2019 08:28 PM

Can someone update this article to work on 4.2.2 or later?

I followed all the steps and the instruction in the posts above and all I could get is the basic HTLM to display. I can't pull in a template with vb:raw at all. Even following the instructions exactly with the code provided and the updates above it still wouldn't pull in any vb:raw info.

--------------- Added [DATE]1551286366[/DATE] at [TIME]1551286366[/TIME] ---------------

Quote:

Originally Posted by Amenadiel (Post 2517287)
I found out that the vbcms_process_widget_complete hook works, but it seems to be inside of a function, so you have to prepend

PHP Code:

global $vbulletin

for the plugin to work.

Can you elaborate on what this means? Sorry I know some PHP but I'm not sure how to implement this fix.

Thanks.


All times are GMT. The time now is 03:01 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01411 seconds
  • Memory Usage 1,831KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)bbcode_html_printable
  • (3)bbcode_php_printable
  • (7)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (33)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete