Archive 1.x:Adding Help to a Layout

Because of its unique presentation and possible inclusion of specialty widgets, it is often helpful to add specific contextual help to a given layout. There are many ways to do so in Drupal. The method we follow is captured below.

Contextual help, which can be invoked or not on any given page in which the field is offered, is obtained via a specific field designation within a Drupal content type (via the CCK, Content Construction Kit module) in interaction with a corresponding code snippet (and styling) within a page layout. Please note that the code additions, the last section below, should actually be added first.

CCK Set-up
To provide the input field for the contextual help, you must first add a new field type to a given Drupal content type. You find this option via. Once the content type is added (or for a content type that already exists), you can then  and  :

In this case, we add a field called  with the label of 'Help Page' and give it a type of 'Node Reference' (see below).

Note: Once this new field has been created, it may be invoked and assigned to other content types by choosing the  option.

The 'Node Reference' type enables us to create a dropdown pick list of existing content types from which we can select our contextual help.

In this instance, we set our list as any one of the 'Page' content types within the system:



Now, any time we create a new content page of this content type, we can invoke this same field set up (by picking the 'Help Page' field option):



Then, within every page that we now create with that content type, we have a 'Help Page' field now available. If we invoke it, we get a listing of all content of the previously assigned content type (all 'Page' listings in this example). The dropdown list shows all of the 'Pages' in the system by their titles. Of course, many of these are simply "normal" pages; but some, as is the one picked in this example, are contextual help pages written for this purpose:



As long as you prepare your contextual help with the proper content type, you can now relate that help to any specific page you create in your local instance.

Note: as the next section shows, we have written the complementary code snippet such that if a help page field is left empty, no icon and no tooltip appears. But, if the field is completed with a link to the contextual help page, both the icon and tooltip appear and clicking on the icon causes the user to be directed to the contextual help page link.

Code Modifications
Invoking the help page involves adding a help icon and tooltip text ("Click here for assistance") as shown below. In the example case, we add code related to the machine-readable field name and place this snippet within a Drupal page's header template, itself called from a standard page template file (such as  or  ). In this example, we include the help icon (if invoked) at the same position as the breadcrumbs listing:

Then, each specific template page also includes a help option:

We are able to set up some styling information for this help inclusion, which is a  called 'page-info':

Of course, these sorts of included code snippets could be placed in other template files or locations. Since headers are a standard inclusion, this location is a convenient way to make the capability available to many template types.