Prevent to Load a js file on particular page using hook_js_alter Drupal 7

Drupal provided the lots of hook to extents its functionality, using this we can prevent a js file to load on particular page using HOOK_JS_ALTER

If you want to load a js on every page except some page, below example will help you to achieving this.

function mymodule_js_alter(&$javascript) {
    $path = current_path();
    if($path == "my-path")


Render block and views block drupal 7 programmatically

This is article is for Drupal 7 to render block in templates and custom blocks using php codes

Actually there is very simple ways to render block pro-grammatically 

1) Module Invoke

$block = module_invoke('module_name', 'block_view', 'delta or machine name of block');
print render($block['content']);

Module invoke is most common way to render a block, above example is self explained or see the below example


How to render i18n translated block in drupal 7 Templates

Hey guys, 

Sometimes we created the themes template in drupal 7 and we need to render custom blocks and views block to display proper diversion, but I face a problem to render block in multilingual site it show the same in both languages.

So I found the solution, hopes it helps to other also 

$block_id = 2;
$block = block_block_view($block_id);
$block['content'] = i18n_string(array('blocks', 'block', $block_id, 'body'), $block['content']);
print render($block['content']);

Just need to update the $block id with yours.


Print array or object in watchdog drupal 7

hey, For many purpose we have to print the array or object while making a custom modules or debuging any old module, we have to print the array or object to see the values are fine or not, drupal provide a way to see those using watchdog, But how we print array or object in watchdog function, Answer is below.

watchdog("any_word_you_like", '<pre>' . print_r( $your_object_variable, true) . '</pre>');

Now, execute your function or page whenever you right it.