Reputation: 64834
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
Upvotes: 1
Views: 121
Reputation: 4873
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'");
}
Upvotes: 3
Reputation: 38418
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.
Upvotes: 1
Reputation: 13226
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.
Upvotes: 1