Overriding a Modules Template File

Now, let's demonstrate how to override a module's default template files, using Comment module's comment-wrapper.tpl.php file as an example. This file doesn't do much more than wrap a div around the comments output. Let's add the text "Comments:" to this file so that it appears above any comments on node pages. We're aiming to achieve what is shown in Figure 11-14.

Superfantastic admin

O My acc

Refoveo View

» Administer rode (story) - Ludus sagaciter sed importunus lobortis lobortis ratis damnum. Ad decet aliguip catión euismod esse. Defui quae vereor,

Feuglat abiuo ratis veniam paulatim zeiüs abiuo diam. Singuiaris odio gui gravis. Meiior ea rreiior jus occuro odio. Esca eligo incassum mos nunc importunus acsi, Jugis exputo ideo vel saepius imputo. Velit damnum loquor enim praemitto. Antehabeo iuptatum tincidunt natu. Cui oiim hos abiuo. Sudo decet esca giivus meiior. Commoveo roto tation distineo commodo vellt lobortis wert o hos ulciscor.

Zelus tation sudo ymo singuiaris dignissim, Jus decet quae. Oppeto roto mauris acsi cogo illum metuo gravis. Nutus te nostrud nisl sino utrum. Similis haero scisco acsi tarnen sino tincidunt. Dolore accumsan eum abiuo importunus. Diam volutpat gemino. Abiuo conventio valde lenis tarnen odio. Facilisis natu ymo ullamcorper. Duis Nie importunus. Quia distineo ibidem jugis quis sino virtus.

Refoveo Saluto Esse Camur Nobis

Refoveo Saluto Esse Camur Nobis

Enim negue modo giivus olim. Pneum causa guibus nutus probo exerci capto defui tincidunt sagaciter,Cogo autem tego dolor lucidus similis lenis genitus, Tincidunt ymo roto augue huic in Nibh torqueo saluto patria. Ad venio olim tation interdico ille macto enim duis. Torqueo haero hos nisi facilisi. Ibidem utinam meiior abigo venio consectetuer minim letalis. Tincidunt utinam vicis giivus sino dolor. Utinam pneum refero ut cui autem nobis capto haero hos.laceo eu vindico pala. Erat ad utinam tincidunt cogo autem. Suscipere decet uxor quae imputo ideo humo nisi fere virtus, Exputo pertineo natu olim. Erat obruo macto exputo imputo. Jugis valde abdo. Meus virtus metuo occuro appellatio. Similis capto ulciscor eum guidne patria esca camur.Os jugis vero gravis suscipere. Typicus appellatio euismod luptatum typicus volutpat abiuo. Incassum gemino eu. Capto qui obruo haero letalis meus immitto vel. Pneum augue probo commoveo. Nimis eros imputo cogo tation virtus valde jumentum vero olim, Torqueo veniam utrum metuo facilisis guibus melior singuiaris. Persto populus occuro mauris blandit incassum fere comis aliguam conventio.Suscipit sudo rusticus si ut pertineo causa lenis. Augue cui nutus. Roto nibh esca humo rusticus eu caecus. Saepius obruo turpis eligo neo. Roto tation acsi jus vulputate validus quidne pneum. Quidne iriure damnum. Consectetuer roto diam cui. Giivus ibidem neo at

Figure 11-14. Comments displayed with "Comments:" above The steps are:

1. Find the file at modules/comment/comment-wrapper.tpl.php and copy it into our theme directory at sites/all/themes/custom/newmarine. Be sure to copy (not move) the file, because the original file will be needed if we ever switch to another theme.

2. Open the new file from your theme directory into your text editor. It contains a lot of comments explaining the available variables:

// $Id: comment-wrapper.tpl.php,v 1.2 2007/08/07 08:39:35 goba Exp $ /**

* file comment-wrapper.tpl.php

* Default theme implementation to wrap comments.

* Available variables:

* - $content: All comments for a given page. Also contains sorting controls

* and comment forms if the site is configured for it.

* The following variables are provided for contextual information.

* - $node: Node object the comments are attached to.

* The constants below the variables show the possible values and should be

* used for comparison.

* - COMMENT_MODE_FLAT_COLLAPSED

* - COMMENT MODE FLAT EXPANDED

1 1

Clear cached data

Caching data improves performance, but may cause problems while troubleshooting new modules, themes, or translations, if outdated information has been cached. To refresh ail cached data on your site, click the button below, Warning: high-traffic sites will experience performance slowdowns while cached data is rebuilt.

Clear cached data

Figure 11-15. The "Clear cached data" button, which should be used if theme changes don't immediately appear

* - COMMENT_MODE_THREADED_COLLAPSED

* - COMMENT_MODE_THREADED_EXPANDED

* - COMMENT_ORDER_NEWEST_FIRST

* - COMMENT_ORDER_OLDEST_FIRST

* - $comment_controls_state

* - COMMENT_CONTROLS_ABOVE

* - COMMENT_CONTROLS_BELOW

* - COMMENT_CONTROLS_ABOVE_BELOW

* - COMMENT_CONTROLS_HIDDEN

* @see template_preprocess_comment_wrapper()

<div id="comments"> <?php print $content; ?> </div>

3. Add a new <h2> element containing Comments:. In our modified example here, we've removed the comments for brevity, but it won't hurt to leave them in. We are also wrapping this text in the t() function so that it is accessible to Drupal's language translation system if needed:

<div id="comments">

<h2 class="title"><?php print t('Comments:'); ?></h2>

4. Remember that in order to get Drupal to recognize this new template, we need to refresh the theme registry, by visiting Administer^Site configurations-Performance (admin/settings/performance) and clicking the "Clear cached data" button shown in Figure 11-15.

admin o My account

► Create content

► Administer o Log out admin

o My account

► Create content

► Administer o Log out

Camur Vulputate Nibh Tation

View Edit node (page) - Bene dolor causa ut at naLris jug is capto cuh Sudo acsi tur luptatum eros abdo lenls eurn. Decet probo virtus natu jus faclilsi facitisf n: allqulp jtrum utrurn aiiquam. Pala olím brevitas virtus abluo dignissirrt mel hendrerit pagus uropnus ulciscor quadrum. Mauris slngularls luctus iusto e pecus ratis si. Refoveo sagaciter Imputo wisi lobortis inure nmim similis. L quldenn laceo. Plaga similis diam ibidem quibus oppeto abico. Dolus slnguli fere. Quadrum abluo val gemino rnellor ex ratis capto. Gllvus deful et íbide

Figure 11-16. The Powered by Drupal block in a new custom region placed above the content

Drupal provides several default regions, as we've discussed. The special "content" region handles blocks in an unexpected way: when you place a block in that region, instead of going above the regular content, it actually goes underneath. There is no way, by default, to add a block on top of your main content area. Well, we have the power of our .info and template files to work with, so let's add a new region so we can put things right where we want them. Figure 11-16 shows a site with a region that has the Powered by Drupal block in it, placed above the content.

1. First, we need to let Drupal know about our region. Open up newmarine.info again and we will define our regions. Remember that in order to add a new region, we need to define all of the regions we want, including the default ones. Add the following lines to the end of the file:

regions[header] = Header regions[left] = Left sidebar regions[right] = Right sidebar regions[content_top] = Content Top regions[content] = Content regions[footer] = Footer

2. Next, we will need to clear the theme cache to make sure Drupal sees the changes we made. Go to AdministersSite configurations-Performance, and click the "Clear cache" button.

3. Go to Administers Site buildingsBlocks (admin/build/block) and when you look at the regions listed, you will see a new one named "Content Top" that we can put our blocks into. Go ahead and drag the "Powered by Drupal" block from the Footer region into the Content Top region and click the "Save blocks" button.

4. You will see that the block has disappeared altogether. It isn't in the footer anymore, and although the Content Top region exists, Drupal doesn't know where to

0 0

Post a comment