Skip to main content
Key2Goal

Main navigation

  • Home
  • About Us
  • Contact us
  • Glossary
  • Privacy Policy
User account menu
  • Log in

Breadcrumb

  1. Home

Render block and views block drupal 7 programmatically

his 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

$block = module_invoke('search', 'block_view', 'search');
print render($block);

2) Using Block Load with delta

$block = block_load('block', '1');
$output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
print $output;

3) Using Block load with Name

$blockObject = block_load('views', 'block_name');
$block = _block_get_renderable_array(_block_render_blocks(array($blockObject)));
$output = drupal_render($block); print $output;

4) Render Views Block

echo views_embed_view('view_machine_name', 'block_1');

5) Render Views Block with Arguments of contextual filters

echo views_embed_view('view_machine_name', 'block_1','arg1','arg2');

Comment for any other help thanks

  • Log in to post comments

Comments

Article category

  • Drupal
  • Wordpress
  • Java
  • Javascipt
  • HTML
  • CSS
  • IOS
  • Android
  • PHP
  • MySQL
  • Other
  • Command line
  • NodeJs
  • Drupal 8
  • Drupal 7
  • GIT
  • DevOps
  • Python
  • Xampp
  • Server
  • Artificial intelligence
  • AppScript

Recent content

  • Differences Between Bootstrap 3 & Bootstrap 4
    2 days ago
  • About Us
    2 days 20 hours ago
  • Privacy Policy
    2 days 21 hours ago
  • Create a Virtual Host on Xampp in 5 steps
    1 month 1 week ago
  • How to setup Multisite in drupal 9
    7 months 3 weeks ago
  • How to creating a FOR loop and a WHILE loop in JavaScript
    7 months 3 weeks ago
  • Calculator program HTML & PHP
    7 months 3 weeks ago
  • Algothrim to create a web application
    7 months 3 weeks ago
  • 10 Git Useful Commands for Every Developer
    7 months 3 weeks ago
  • Top 10 useful commands for GIT with example
    7 months 3 weeks ago
© Copyright 2017 - 2026 key2Goal. All Rights Reserved