I have a view located here

I have uploaded a test.pdf file in the agenda section for the July meeting.

I want this to be able to say "Download Agenda" but only when there is an agenda uploaded to that field.

Do i add code to a views theme? Can anyone assist me with this code?

I know in a node.tpl.php file it would be something like this but i am just not sure where to put this code.

if($node->field_file[0]['filepath']) != ""):
print l(t('Download Article'), file_create_url($node->field_file[0]['filepath']));
endif;

thanks!
andrea

Comments

zbricoleur’s picture

Look in the /views/theme directory. You will find several templates there. Place a copy of the appropriate template in your theme directory, modify it to suit your needs, and refresh your cache.

abelb’s picture

i created a theme called: views-view-field--field-agenda-fid.tpl.php but i don't think i am getting the proper PHP code syntax. perhaps it is not the right theme to be adding the code to.

Can you point me to the correct theme?

thanks!
a

zbricoleur’s picture

Look in the /views/theme directory. Most likely, given what you are trying to do, the template you're looking for is views-view-field.tpl.php. Make a copy of that template in the directory for your site's theme. You will have to refresh your cache then to get Drupal to pick it up. It will then override the default theming.

Then modify it as needed to get what you are after.

glennnz’s picture

How do I restrict the theme override to one particular View?

I have several unformatted style views, but just want to change one particular one...

Thanks

Glenn

Glenn
THECA Group

Bensbury’s picture

Go to your view and click the Theme option in the menu.

It'll give you a list of views templates you can use.

Or you can use FF and Firebug and often the view gives it's name away in the class id.

Personally I go to the views module folder, and then copy what I want into my theme.
Then to extend it using the the name from the theme options.

However to give you a clue here are some examples....

views-view-unformatted--Topics--page-3.tpl
(this is for my view named Topic, and the page-3 part refers to the 3rd display I have.)

view-view-field--Topics--page2.tpl -- Is a template for all the fields in my view Topic and for the second display, which I stripped of html to make a mobile feed.

view-view-field--Topics.tpl would be a template for all fields in my TOpic view.

And for a super long one@

views-view-field--Works--page2--field--picture--fid.tpl

This singles out the picture field, on the second display or my Works view.

Hopefully from these examples you'll see how it works out.
Like was written about, always flush the registry cache.
I usually just write a few stupid words in first to check the .tpl is being picked up.

I hope that helps you out.
After doing a few super longs ones, you start to understand the pattern across all the templates, so it's worth persisting at.

AaronA’s picture

Well, the Devel module is a prerequisite for what they now call the Theme Developer Module. It lets you see which functions are generating what elements in your theme. Very useful for figuring out exactly which views template is being called, its (quoting the writeup about it) kind of like Firebug for Drupal. It has saved me enormous amounts of time in the past, not only for theming views, but for general theme functionality.