You are hereTemplates

Templates


Omega 4 and Compiling Sass on Windows (how to install and make it work)

I know Sass and Less are major improvements in Css coding, but setting all this up is a drag. I was using Omega 4 and to style it we need to use Sass coding. There are enough resources out there, but they are often limited to some special use case scenario and as there are many components to make it work you will have problems when trying to set it up. So after a day of work I finally pulled it off and made this Sass thing work and auto compile to Css.

Add UTM tag to links, so other people know when users come from your site

So this is some marketing stuff I do, but it is useful. When you click a link on some site, to give some message to that site and owner or whoevere is taking care of marketing you can add some UTM tags to links so in their google analytics they see that message. So what do we do is I use display suite, create custom code field and use entity data to make new fields that look like this:

<?php

if (!empty($entity->field_collegamento)){
foreach ($entity->field_collegamento['und'] as $key => $value) {

Removing title from Page to use title from Node or how to make templates for pages per node type

Drupal is great :)) well not so much, it is made in a way that you will always have love/hate relationship with it. So somebody thought that best way to make templates is to have title and h1 tag always in page template separated from the rest of the content, which is fine if you are doing pages in 2002. If you want to have nice header with image of author, date and some other info and display it like you want and not have to use panels just to do that, you have to override, which is ok, but then again somebody else thought, why would you want to override pages by node type.

Theming Ubercart Order Admin or uc_order-admin.tpl.php

So this one is rather old in 2013. But then again Ubercart and E-commerce are slowly getting up to speed with drupal 7 so still many sites use Drupal 6 for web shops. Anyhow, what we wanted to do is add some extra information to emails sent after order. Ubercart has a way of sending nice HTML emails to clients and obscure plain text emails to admins. Which is ok by me and in drupal 7 it is easily replaced and set up by additional email modules like MailSystem I think https://drupal.org/project/mailsystem which integrates with UberCart in drupal 7.

Webform mail template override - total customization

I wanted to make a override of webform mail template, so I can send custom data to paying and non paying partners on my site. As I am using ZEN subtheme, I need to put all the the template in obviously template folder of subtheme, not a root one. Find a default template file in webform module webform-mail.tpl.php and make it something like webform-mail-174.tpl.php, 174 being a nid of your webform. So in order to make this override work. You also need to choose carefully in your webform UI.

Drupal 7 imagecache, theming images in templates

Creating images in your templates in drupal 7 is somewhat different, so here is the code

<?php
$hero_image = array(
'style_name' => 'case_study_teaser',
'path' => $image['uri'],
'width' => '',
'height' => '',
'alt' => $image['alt'],
'title' => $image['title'],
);
print theme('image_style',$hero_image);

$img_url = 'public://myimagefolder/imgfilename.jpg'; // the orig image uri
$style = 'thumbnail'; // or any other custom image style you've created via /admin/config/media/image-styles
?>

Translating taxonomy summary in views

Here is another drupal i18n beast. I have nice taxonomy summary for a category of shops. Which is attachment for a view, which passes term to it to filter category and show only shops that are in that category. Looks nice, it is moderately useful and seems it has never been done before. Search for something similar never came up in google, only a rather useful post that deals with similar stuff, only much simpler, people want to translate term title.

Microdata and Fivestar

Microformats are going to be big, they are big even today. Drupal is caching up but modules don't work properly. First thing you would probably do is ratings/review formating. You can try with microformat and fivestar module but it will not work properly. So I themed the fivestar summary function differently and added few lines and not it works and you can check it with google tool

http://www.google.com/webmasters/tools/richsnippets

Just copy this to your template.php or use some diff tool to see what is different
http://www.quickdiff.com/

Drupal 6 to drupal 7 migration tips

However you choose to do a migration from drupal 6 to drupal 7 if you have any complexity in your site it is going to be ugly. Lots of errors and leaps of faith :-).

I choose to do it with drush. So after the drush made what it could do. I tested the site. Not working at all, not even logging in possible. What I did is:

Files: 

Custom Token and languages for titles and labels

As views and even more panels are not perfect when it comes to translations if you need to have some fixed label with translation for some view/panel. You can create custom token for it and then just translate it over translation interface. Token creation is simple, just use this guide

1. Go to Admin > Structure > Custom Token, click on Add Token
2. Enter a Token Name and Description
3. Choose "Custom Tokens" for the Token Type or "Nodes Token" if you want it to be available on for example node panels overide.
4. In the PHP Replacement text area enter something like this: