I am running Drupal 6.15 and Views 6.x.2.8. I use the standard "Garland" theme and have no custom themes installed. My /sites/all/themes/ directory is therefore empty (before I copy my custom template into it).
I have created a View (named "blogpages") with a fields row style. I have also created a "Page" display for that View.
And now want to override the way one of the fields is displayed on that Page. I have read a lot of tutorials about how to do this. As far as I understand them, they tell you to click on the "Theme: Information" link in the Views 2 UI to get up a list of template files, pick the one you want to modify, copy it to "your theme directory", rename it to include the name of the field you want it to apply to, modify it, flush the cache - and voila!
I want to modify the way a field named "name" is displayed, so I've copied views-view-field.tpl.php → views-view-field--name.tpl.php, and placed the modified file in the directory /sites/all/themes/ below the Drupal root. My modification is to replace the following php statement in the file: print $output; with: print "custom" . $output;
I can't get this to work. Drupal will only display the name field using its standard template, not my custom template.
Can anyone tell me what I do wrong, or point me to a really good tutorial about how to apply a custom template to a field in a view?
Comments
you need to rescan template file when looking at views templates
..when your creating the view -> see the video at mustardseedmedia website.
Hope this helps?
Rescanning template files does not help
I have alredy tried to press the "Rescan template files" button in the Views UI (i.e. flush the cache), but this has no effect. If I've understood things correctly, doing so should boldface the modified files in the "Theming information" panel. This does not happen. This indicates that Drupal does not find or see my custom template files. However, I have no idea why,
- gisle
The template needs to go in
The template needs to go in /sites/all/themes/your_theme
Thanks!
However, I may be a bit slow, so please excuse me asking for an even bigger teaspoon.
I don't have a directory named "your_theme". And since I don't have a custom theme (I just use the default Garland), I don't have a theme that I is "my" theme. Do I go ahead and create a directory named "your_theme", or what?
*Update*
Creating a directory /sites/all/themes/my_garland/, copying the entire contents of /themes/garland/ into it, switching to the "My Garland" theme and finally copying my custom template files into /sites/all/themes/my_garland/, solved it (sort off - the custom templates are now found and used).
However, I wonder if this is the right way to do this? I really don't want to keep maintaing a non-core "My Garland" theme. I want to keep the core intact, and just override a single field display. Is there a way to do this?
- gisle
your_theme is simply the
your_theme is simply the theme you are using, you can place the templates directly in the garland theme directory.
Should one modify the core?
The /themes/garland/ directory is part of the core distribution.
I thought that one of the hard rules of Drupal was that you never make your modifications part of the core. If you do, you will loose them the next time the core is updated (unless you take special measures to keep them).
I am suprised that Drupal theme engine does not also look for overrides in the /sites/all/themes/ directory. If it did, you could create some basic overrides (of the display of something like a single field), and have it apply to all themes.
@mtsanford
Thanks! I'll look into the sub-theme approach.
- gisle
The way I look at it is if I
The way I look at it is if I am adding files (i.e. .tpl.php files) I am really extending the theme and updates will not override my additions.
If you are changing existing files it is best to either copy the theme or make a sub-theme
If you want to the this the
If you want to the this the 100% correct Drupal way, you'd make a sub-theme with Garland as the base theme. Never done this myself, but there are docs for it:
http://drupal.org/node/225125
very similar situation
For my view user-list, I have just one modified view template file (views-view-fields--user-list.tpl.php), which I want to work for all themes... do i really have to copy this file into each of my 5 theme directories? What if I want to make a change? I have to make the same change to all the other duplicate files?
An option there would be to
An option there would be to make your 5 themes a subtheme of a new one. You just put your template file in that new theme and it will be used by the other ones as well.
Thank you so much SOSv2, this
Thank you so much SOSv2, this is the perfect (and obviously "correct") solution to my problem. It is a technique I'm sure I will use a lot!