Blog



Custom templating Fields/CCK field output

24 Feb 2011

The Drupal theming and templating possibilities are endless and once you get how it's done it's a breeze! I say once you get it, because you can have a hard time figuring out how. For the next version of my portfolio website, which I'm building in Drupal 7, I had a hard time figuring out how to override the HTML that was generated automatically by Drupal for a Fields (former CCK) field. I had a custom content type with a multiple value image field from Fields (the 'new'  CCK in Drupal 7) plus some other more standard fields.

Working with the Views 2 module and creating some custom templates for the output I was able to generate my own clean and minimal HTML without all the extra div's and wrappers the Views Module can provide. There was however one problem, I could not figure out how to have the image field rendered without the div wrapper and field label divs. Here's what it looked like:

<div class="Custom-Div">
<div class="field field-name-field-photo field-type-image field-label-hidden">
<div class="field-items">
<div class="field-item even"><img alt="" /></div>
</div>
</div>
</div>

Now that's a lot of DIV! What I wanted to achieve was to loose all the extra DIV's and just have my Custom-Div containing all the image fields, like this:

<div class="Custom-Div">
    <img ..... />
    <img ..... />
    ..................
</div>

At first I thought this could easily be achieved with the Views templating possibilities, using views-view-fields.tpl.php to customize my output. For all fields that worked fine except for this Fields/CCK image field! Searching for options in other Views templates or writing out the raw query result via some custom code couldn't help me. Then all of a sudden I started realising I was looking in the wrong place! The extra HTML was generated because this image field was a Fields (CCK) field added to the content type. I found an article explaining this for the Drupal 6 CCK fields. So I started searching for the same info in my Drupal folders in the Fields section and voila!

Fields/CCK have a custom theme function for generating the field output! And it works almost similar overwriting this with you custom code. Even for single CCK fields. You can find the file field.tpl.php in the Fields module folder structure that comes with Drupal 7 core. Just copy this file to your theme folder, modify it to your needs and you're done!


If you want it to apply to only one certain field use the name of that field in the file name like field-[FIELD_NAME].tpl.php. Heck, you can even narrow it down to certain content types by adding field-[FIELD_NAME]-[CONTENT_TYPE].tpl.php to the file name.

Sometimes, the simplest solutions are the hardest to find.



Renate and Fabrizio wedding shoot

25 Jun 2010

A couple of months ago I was asked if I was able to do the wedding shoot for a befriended couple. I was thinking about creating some opportunity to do a wedding shoot, but now with them getting married, what's better than a befriended couple. They had already seen some of my work and really liked the idea of me making those shots instead of a unknown photographer. The plan was to do a whole day shoot, with the bride preparing, the pickup, a shoot in the park, the ceremony , etc, etc. With these big responsibilities I had to dive into the subject!

I started googling away to prepare myself more on the topic and learn from others. Shooting away for 12 hours was something I've never done before. Next to that there was something at stake here: a good wedding shoot. So as I said, I started to google and scan the net for wedding photography tips and examples. Some photographers that really helped me out with their sites/blogs were Bert Stephani and Tom Leuntjens. Especially tom's site and blog stood out as an excellent source for info on wedding shoots. He has a couple of articles about how he prepared for his first wedding shoot, going from preparations, gearlist, motivations, to the actual wedding day. Definitely worth a read if you're into the subject. Also, the Flickr communnity paid out well with tons of inspiration (including the great shots by Bryan Renizer) You can check some photos from that day below and a lot more on my Flickr account. It was an inspiring (and tiring) day and we had a lot of fun!  

More photos of this shoot in the wedding photography folder



Siurana, Espana

10 Jan 2010

SiuranaSpain, a lovely country with many faces. The culture is wonderful and the country has such a rich and long history. We visited Spain numerous times the past years, on vacation and to visit family, and next to the beach and sunbathing we like to explore, and see what else Spain has to offer.

What most tourists at the costas don't see, is the beauty of the countryside and the quiet small villages with pittoresque churches and architecture. One of those places, in the Costa Daurada region, is Siurana.

 

Siurana streetSiurana is a town with a long history. As early as the year 900 the Moors had built a castle on top of the rock. A strategic location, because you can see for miles at the top. Some centuries later, during the Reconquista, the village came into christian hands again, and developed itself through the mediaeval period.  Siurana has been well preserved over time and the layout, a lot of the buildings and the streets are still in their mediaeval glory, be it restored. All that time the ruins of the old Moors' castle remained.

Today Siurana is only well known in the world of climbing, as the rocks it sits on are popular in the climbing world. They go very steep and make this village even more impressive. Also, the road to the village is breathtaking with views of rocks and mountains, and the big curly reservoir below.

We have great memories of this little village, so beautiful, peaceful and calm. A must visit location if you are ever in the neighbourhood. More photos in the 'travel' section.

Siurana view



2010 must-read starters

05 Jan 2010

IE6 out image by RobotJohnny.comHappy new year and best wishes for 2010. And it'll be a promising year!
Here some topics you might have already heard of or read about on the web if you're into webdesign, development and all else that is front-end. If you haven't then it's reading time for you, because these topics really picked up speed in 2009, and I hope to hear and see more about them this year. So these things need word of mouth.

 

Scrollbars....hmmmmmmmm:

More and more I read blog post and articles referring to conventions we disliked in the past, but are currently turning around, or get more consensus. It does also come together with changing technologies like screen resolutions, internet connection speeds , etc. (ah..... progress) but it just feels like we're really getting into the next phase of the development of the web. Scrolling for instance, it was very important not to too far beyond the screen bottom with your important content, concentrate your important content above the 'fold', but no more: "It's ok to scroll"

Bye bye IE6:

IE6 is out. Every day more people denounce it officially: "Bye  bye IE6"! Now, visitors using IE6 get custom I-do-not-support-IE6 pages, messages blocks or only get to view the site in minimal boring visual style  with barron IE6 css stylesheets. It got picked up by the big sites as well. It's a revolt! And I'm glad it's here.

Type:

Typography gets bigger and bigger. It seems you need a type of text replacement thingy on a website now. There are several ways, each with it's own pros and cons. As always, embrace it, use it wel but use it wisely and sparsely!

24 new ways:

And as allways at the end of the year, the excellent 24ways! Enough to catch up on.



How to get Drupal Views render-as-link-fields W3C compliant

08 Dec 2009

W3c compliant logo imageEdit jan. 2011: The solution below is outdated. Views has been updated and so has my knowledge of Drupal in the past years. ;). There are better ways to solve this.

I love Drupal. What's not to love about it? The steep learning curve? Come on, better stay with Wordpress then you. For al you other people who took the 'elbow greased' plunge like I did, a tip on the Views module. The Views module in Drupal allows you to make your own pages, blocks, etc with the content you would like to have on it from the different content types. There is no limitation! And that's what makes Drupal so great and flexible. Recently however, I stumbled upon a spec on this immaculate module.

It has to do with the fact you can write out a field with Views and have it render as a link. When this option is selected, it generates exactly what it should do. However....., those fields get an alt attribute (version used D6.x - Views2.8), and that's not what we want on the A tag. The XHTML Strict 1.0 doctype does not like 'alt' attributes in the A tag. In the IMG tag, ok. So how do we get rid of this and have a strict compliant page? It's easy!

In Views there is a function that generates this alt attribute and the title attribute as well. It's render_as_link or render_link which is located in the file modules/views/modules/node/views_handler_field_node.inc. Together with some code in modules/views/handlers/views_handler_field.inc approx. at line 517, the alt and title attributes are generated:

$alt = $this->options['alter']['alt'];
$alt = strtr($alt, $tokens);
if ($alt) {
$options['attributes']['title'] = $alt;
$options['attributes']['alt'] = $alt;

All you have to do is take out the piece of code that's writing out the alt attribute. Save it and see the alt disappear on all those links on your site! There's a patch or it as well on the Drupal site. More info can be found there as well.

Pages

Copyright ©2005-2011 Sebastiaan Bonardt. All Rights Reserved.