You are hereBlock help

Block help


Display Block for specific Content Type

This is how to do this, choose PHP for block visibility mode and add the code below,
choose in types, array your content type

<?php
$match = FALSE;
$types = array('my_content_type' => 1);
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
$node = node_load(array('nid' => $nid));
$type = $node->type;
if (isset($types[$type])) {
$match = TRUE;
}
}

return $match;
?>

Gmap center and resize when block is collapsed

When you have a problem with google map when hiding or collapsing it within a block you need to do something to fix this. A way to do this is to make gmap block absolute in position and -10000 px in left like

#block-gmap_location-0{
position: absolute;
left: -10000px;
}

and then use jquery to show it with js script

$('#block-gmap_location-0').css("position","relative");
$('#block-gmap_location-0').css("left","0px");

and finally map is fixed and working.

Simple google map

You want simple google map without some extra modules, API keys etc? This is rather simple, all you need is to go to google maps, choose your location and go to upper right corner where is "Paste HTML to embed in website" code, copy that code. Go to Block sections in your drupal administration, create new block and place that code in block. Use Full HTML input format so all html can pass and there you go, you will have a block with a map. You can edit width and hight in code, edit lable below it and customize it to your needs. Same way you can do with all other maps like BING etc.

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'];

Form Block and reference field

Form Block module enables you to create nodes from block, so you can have some text and under it block for entering data for node type lets use "tips". This is similar to commenting then but you can have much more power this way.  But how then do you connect this new node with current on screen?  You add to that "tips" node type a reference field, that would connect it to node on which this data was entered.

Node loading, simple variable passing to flash banner

So in previous post with made drupal custom block now lets make custom block with flash banner where data to banner is passed from node that has CCK fields.Make content type with 4 cck text fields, or just use one field, even body can do and then you can manauly manipulate string with PHP, just have some separator in your input. In this example we will use 4 cck fields.So in the block template, block-block-4.tpl.php we add this code

<?php $nid='51';$node = node_load(array("nid" => $nid));?>

Custom block

Sometimes you want to customize block more then its available through drupal admin, then you start themeing. Quickest way is to copy default block.tpl.php file and then edit its name to something you want to customize. Lets say we customize block number 4, which is block created with views, then you make your file name like "block-block-4.tpl.php" and then change its content. For this to work you have to have block.tpl.php also in your theme folder.

You can dowload php file like that below!