views:

60

answers:

3

hi,

I've just started to create my own modules to make my custom functions such as hook_form_alter() etc...

Now I was actually wondering how can I use custom modules to make small changes to some modules. For example, consider the View module, I want to modify the file: "views-view.tpl.php" .. let's say change the name of the class of this div

...
<div class="view-filters">
      <?php print $exposed; ?>
    </div>

How can I make it without hacking the code ?

thanks

+1  A: 

The easiest way to change what tpl is being used for a view is to provide a TPL to the view to use. If you click on Theme: Information in a view, it will list various ways you can override the output from the entire view down to the field level.

Kevin
+1  A: 

It's rare that you need to edit a contributed module or the core (if that's what you mean by hacking).

The answer is yes!

Having said that, some modules are written poorly. If you can't write an interface to it or fork it, you'll need to hack it and submit a patch to the project's issue queue. Then your changes might be included in the next release.

Rimian
+3  A: 

In order to change the CSS class for the .views-filters div, you need to provides an alternate views-view.tpl.php (or views-view--VIEWNAME.tpl.php or views-view--VIEWNAME--DISPLAYID.tpl.php). This is usually and easily done in the theme. But if required, it can be done from a module too:

function YOURMODULE_registry_alter($theme_registry) {
  $originalpath = array_shift($theme_registry['TEMPLATE']['theme paths']);
  $modulepath = drupal_get_path('module', 'YOURMODULE') .'/themes');
  array_unshift($theme_registry['TEMPLATE']['theme paths'], $originalpath, $modulepath);
}

This allow you to place an overriding views-view.tpl.php template file in the themes directory of your module. In order for this to work, your feature should have a weight greater than the one of the module providing the overrided template. So in your module install file (YOURMODULE.install) you will have something like

function YOURMODULE_install() {
   db_query("UPDATE {system} SET weight = 10 WHERE name = 'YOURMODULE'");
}
mongolito404
I agree. Keep in mind that there is a difference between theming (theme_ functions and tpl.php templates) and the module's behavior written in PHP code. When you need to change the html output a module produces, that's called theming, and the most logical place to do that is in your theme. When you need to change how a module works, try to do it in a custom module by implementing hooks (like you do with hook_form_alter).
marcvangend
ok cool! The solution is just to copy paste the template file in the theme folder.
Patrick

related questions