Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 4 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
[HOW-TO vB4] Create a Widget using Plugins and Templates
Mythotical
Join Date: Jun 2004
Posts: 1,428

 

Booneville, AR, USA
Show Printable Version Email this Page Subscription
Mythotical Mythotical is offline 02-17-2010, 10:00 PM

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



Step 1a. - Widget Creation - Details

Click Create Widget at the bottom of this new page.



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.



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.



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.



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.



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.



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.



Step 4. - Add Widget Template

Go to: AdminCP > Styles & Templates > Style Manager



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.



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.



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)



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



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



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

Reply With Quote
  #32  
Old 08-07-2012, 07:05 PM
Draffi Draffi is offline
 
Join Date: Oct 2011
Posts: 80
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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!
Reply With Quote
  #33  
Old 10-01-2014, 07:17 PM
Amenadiel's Avatar
Amenadiel Amenadiel is offline
 
Join Date: Sep 2006
Posts: 171
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Badshah93 View Post
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.
Reply With Quote
Благодарность от:
tbworld
  #34  
Old 02-26-2019, 08:28 PM
Scalemotorcars's Avatar
Scalemotorcars Scalemotorcars is offline
 
Join Date: Mar 2006
Location: NC
Posts: 619
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 View Post
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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:47 AM.


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.03705 seconds
  • Memory Usage 2,258KB
  • Queries Executed 20 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_code
  • (1)bbcode_html
  • (3)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (4)post_thanks_box
  • (4)post_thanks_box_bit
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (4)post_thanks_postbit_info
  • (3)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete