
Tonight sees me writing a very frustrated Drupal post, but I've googled until my eyes went googly and I can't see a solution.
So I turn to you, lovely people of Drupal Planet. I need your expertise and advice. And possibly a sample .tpl.php file...
Here's my problem - I'm using views to create a block for the sidebar of my site. What I want to do is display a list of latest content showing the title of the post and an ImageField thumbnail. Examples of what I'm trying to achieve are on Daily Mail and Holy Moly - both on their right-hand sidebars.
Where I'm struggling is that I want granular control over the display output. I want to build the <img> tag manually, pulling the node title in as the ALT and TITLE tag for each listing.
I'm using an unformatted view type and the fields display. I can't select the whole image field because that's a pre-configured HTML string. And the 'meta' version is seemingly useless. I've also played around with block-specific template files, but nothing has worked.
So, over to you Drupal geniuses! Hit me with your best solution, because I'm fresh out of ideas!
Maybe you should try the
By Boris (not verified) on 28 January, 2011 - 08:43
Maybe you should try the module VIEWS_CUSTOMFIELD, http://drupal.org/project/views_customfield
With this you can use php code to create flexible field outputs, e.g. using theme('imagecache', ...).
Good luck!
You dont need a tpl.php to do
By Abhijit (not verified) on 28 January, 2011 - 08:49
You dont need a tpl.php to do this. In views add the node:title as a field. Add the image (this should be from an image-field), and for the "Format" in the image, select "URL to file" and check "Exclude from display" to hide this image field. Add a "Global:Custom text" field. In the "Text" section of this field write - <img src="[field_image_fid]" alt="[title]" title="[title]" />, where [field_image_fid] is the image field token and [title] is the title field token. These tokens are available in the "Replacement patterns" fieldset below the field textarea. That should get you all set! Enjoy!!
Awesome solution, Abhijit - I
By gerard on 28 January, 2011 - 12:08
Awesome solution, Abhijit - I didn't know this functionality even existed in Views. You've taken my knowledge of Views theming to a whole new level. My block is now available on Unreality Shout's right sidebar - and I'll do a write-up of this technique when I get a few moments!
Genuine thanks - I'm sure everybody reading this understands exactly how much time you've saved me!
Hi, can anyone advise how to
By sdk (not verified) on 13 April, 2011 - 15:23
Hi, can anyone advise how to do it in D7 ?
Thanks
Abhijit's right. Just bring
By dixhuit (not verified) on 28 January, 2011 - 11:24
Abhijit's right. Just bring in the fields you want to reference but exclude them from the display. Then either add a custom text field or override the output of another field and put your custom code there. You can then include tokens that refrence the fields that you excluded from display.
I confirm that Abhijit
By Anonymous (not verified) on 28 January, 2011 - 11:47
I confirm that Abhijit solution works and i have used something like that in my own sites. Good luck
This just blew my mind. I've
By Matt (not verified) on 28 January, 2011 - 13:55
This just blew my mind. I've built countless views using complicated template overrides which would be greatly simplified using this technique. Amazing.
Matt
Saw this on the Drupal
By tzoscott (not verified) on 28 January, 2011 - 14:04
Saw this on the Drupal aggregator, and came here to provide the answer (Abhijit beat me to it, well done).
As you see now - get your view to provide the raw material first, and then you can assemble it together. Most of the time, this works and you can ignore the Views defaults and "roll your own" markup element using the raw bits.
The times where Views output becomes a bit more complicated are when you want one field to have access to another field's data, or you want to combine data from different $rows. Only then do you start needing to mess around with PHP regular expressions (and you end up either 1 theme layer up or down from where you thought you should be working). In these cases I always spend a few minutes wondering if there's any other way (and there probably is, if I write a views handler), and then I dive in and start rewriting the output in PHP. But most of the time, the answer is right there in Views tokebs. :-)
Thanks for stopping by and
By gerard on 28 January, 2011 - 16:14
Thanks for stopping by and filling in a bit of extra detail though! What happens if you want to do something conditional with the output - like handling rows that don't have imagecache fields differently to those that do?
You gotta be kidding man...
By Felipe Fidelix (not verified) on 28 January, 2011 - 21:45
You gotta be kidding man... Asking for help on Drupal Planet? WTF are you thinking?
The Forums, the Mailing list and the IRC channels are for that!
Oh, the audacity! Sorry
By gerard on 28 January, 2011 - 21:53
Oh, the audacity! Sorry Felipe, I figured I've shared a few Drupal howto posts on Drupal Planet, people probably wouldn't mind answering a question. And at least two Drupallers have gained new insight from this post, so mission accomplished :)
Please Gerard, read this
By Felipe Fidelix (not verified) on 28 January, 2011 - 22:11
Please Gerard, read this post:
http://shellmultimedia.com/blog/come-join-us-building-consensus-best-use-planet-drupal
This post describes what I mean. Please don't use planet to create posts like this.
Great post; as a beginner
By wordjuggler (not verified) on 18 February, 2011 - 00:17
Great post; as a beginner building my own site I have been trying to work this out for days.
I like Drupal (have worked with a preconfigured Drupal site at work for a while now) but the learning curve is steep, even for a semi-geeky person.
Yes, there are resources on the net, but a lot assume knowledge of CSS or PHP which many people don't have, so it's refreshing to see something explained so clearly.
Could anyone please post an
By Anonymous (not verified) on 27 April, 2011 - 14:42
Could anyone please post an advance newsletter module(other than simplenews) I have an urgent requirement.
Thanks in advance
can anyone tell how to theme
By Anonymous (not verified) on 14 July, 2011 - 12:05
can anyone tell how to theme the views. how can we override the .tpl files of views
Add new comment