You are hereTemplates help

Templates help


CSS in IE8 list tag(LI) in one row

I just encontured stupid problem with IE and listing LI tags in one a row, If you want to list them properly and not skip into second you need to add some
white-space: no-wrap; to work to LI or in fact A tag inside LI. Those having that problem will know what I am talking about.

Converting Date timestamp to proper Date

If you have some variable in your node object or somewhere else like [created] = 1328281634 then you need to convert this to date format you like, so you can do it
with line like this, where you choose custom date format

format_date($timestamp, 'custom', 'D, j M, Y \a\\t G:i' );

or use some predefined date format on your site like

format_date($timestamp, 'small');
format_date($timestamp, 'large');

For custom formating look here PHP Date

Imagecache output in template.php

Sometimes when theming on some level you need to output some image through imagecache, so here is how to do it. Usually in some function in template.php you will write this

$node_img = theme('imagecache', 'Nletter', $node->field_naslovna[0]['filepath'], $node->field_naslovna[0]['alt'], $node->field_naslovna[0]['title'], null);

Where "Nletter" is the name of imagecache and "field_naslovna" is the name of the CCK field.

Fusion theme classes for node add and node edit pages

I almost always use Fusion theme as my base theme, one thing its missing and developers of it seem not to care is a class that is in body and is different for node add and node edit pages, so I usually go to template.php and around line 64, after

else {
$body_classes[] = (arg(0) == 'forum') ? 'forum' : ''; // Forum page
}

I add this two

$body_classes[] = (arg(1) == 'add') ? 'node-edit' : '';
$body_classes[] = (arg(2) == 'edit') ? 'node-edit' : '';

Box Shadow in IE7 and IE8

Finally in IE9 MS started to support proper and useful CSS tags. But at this moment in time you still need to have support for IE7 and IE8. So If you want to make some nice box shadows, you are in a problem. Luckly this page comes to help http://css3pie.com/
works as it should, donate to those people, they made your life much easier :-)

Just a note on this. when adding this to your CSS, put in an path to your CSS files and this .htc file like

.region-page-closure{
background-image:url("../images/miletic_footer_bg.png");
background-repeat:repeat-x;

Custom imagecache output of image

You are looping through some arrays and you have some image variable, path of original image. You want to print out some variation of that image, this is what you do

print theme('imagecache', 'User_profile', $viewPred[0]->users_picture, $alt, $title, $attributes);

User_profile is imagecache variation and after that is variable where path of our original image is stored. I got that variable from a drupal view but you could get it in some block, or page file or wherever.

Get and loop results from view

You constructed a view and want to get view results and fine tune some usage of them by PHP this is how you get them

$view = views_get_view_result('Name_of_View'); print_r($view);

You will get classic array of values where you can choose which one you want to use and print out. You can also add name of display you want to use.

$view = views_get_view_result('Name_of_View', 'block_1'); print_r($view);

Block output and Views output in theme with module_invoke

Every now and then i need to make some custom output of a block, either in some page.tpl.php file or in a drupa interface custom block, either way you can get it with module_invoke function

$block = module_invoke('nice_menus', 'block', 'view', 1); print $block['content'];

Printing out all variables

Before we learned how to print node variables now lets see how to get all variables that are present on page

<pre>
   <?php print_r(get_defined_vars()); ?>
</pre> 

is put in the code on your page.tpl.php, maybe you can get some nicer view of this with devel module and kumo output.

Printing out Node Variables nicely

You often have to print out node variables to see what you need to do. There are few ways to do that, before i used Drupal Themer for doing this which is part of Devel module. But this is very slow module and it takes a lot of time to load so i am not using it anymore. You can either use dpm function from devel module to dump something to screen nicely or just using plain old

<pre><?php print_r ($node); ?></pre>.

Will get you printed node structure. So past that into your code, node.tpl.php or page.tpl.php.