Use the Drupal Widgets Module For Reusable Content

widgets

The Widgets module allows you to centrally manage text and code snippets across your Drupal site.

You can also combine the snippets into sets for even easier re-use.

Widgets provides some pre-defined snippets but also allows you create your own. In this tutorial we’re going to do both.

We’re going to show you how to:

  1. Use pre-defined widgets to show social bookmarks on your site.
  2. Create your own reusable content.

Using the Widget Module to Add Social Bookmarks

Install both of these modules:

Enable both of those Widgets modules:

tutuploadsmedia_1337699830252.png

Also, we’re going to enable several of the Service Links modules. Which ones you choose will depend on the target audience for the site, but enabling the following three options will give me Facebook, Twitter, Google Plus and other popular options.

  • Favorite Services
  • General Services
  • Widget Services
tutuploadsmedia_1337700051651.png
  • Go to Structure > Blocks and publish the Widgets: widgets_service_link-default module.
tutuploadsmedia_1337699866780.png

The module will look like this on the front of your site:

tutuploadsmedia_1337700302017.png
  • If you want to modify that block, go to Structure > Blocks > Widgets.
  • You’ll see that your service links widget is the only availabe at the moment.
tutuploadsmedia_1337700351946.png
  • Click Edit.
  • Click Override defaults at the bottom of the page.
  • You can now rearrange all of the social icons and also add more.
tutuploadsmedia_1337700501045.png

Creating Your Own Widgets

Widgets also allows you to create your own reusable widgets.

To make full use of the power of custom widget, install and enable these two modules:

Those two modules will allow our widgets to be much more fexible.

  • Go to Structure > Widgets > Definitions.
  • Click Add widget definition.
  • Definition name: Enter a name for your new widget.
  • Template: Enter the text or code you want to use. You can use tokens. You can find the tokens for your site by clicking Help > Token.
tutuploadsmedia_1337701184317.png
  • Repeat the process with another widget:
tutuploadsmedia_1337701120480.png

Now we’re going to join the two widgets together into a widget set.

  • Click the Sets tab.
  • Click Add widget set.
  • Enter a Set name.
  • Click Create new set.
tutuploadsmedia_1337701314825.png
  • You can now add any of the widgets. We’re going to add the new widgets that we have just created.
tutuploadsmedia_1337701354506.png
  • When you’re finished, the widget set will look like the image below:
tutuploadsmedia_1337701390186.png
  • Save the widget set.
  • Go to Structure > Blocks and your widget will now show as a block. Publish this block.
tutuploadsmedia_1337701414661.png
  • You should now be able to see the widget set live on the site.
tutuploadsmedia_1337701490572.png
  • You’ll also be able to re-use this widget almost anywhere on the site using tokens. Your new widget set will appear in the list of available tokens found in Help > Token.
tutuploadsmedia_1337701706493.png

Author

  • Steve Burge

    Steve is the founder of OSTraining. Originally from the UK, he now lives in Sarasota in the USA. Steve's work straddles the line between teaching and web development.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x