snipt

Ctrl+h for KB shortcuts

PHP

Drupal 7 load block view in a template file

1
2
3
4
5
<?php
      $block_to_load = block_load('views', 'your_block_name'); 
      $output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block_to_load))));       
      print $output;
?>
https://snipt.net/embed/788cb4c2cf52fd4307a1966341e748c6/
/raw/788cb4c2cf52fd4307a1966341e748c6/
788cb4c2cf52fd4307a1966341e748c6
php
PHP
5
2019-07-15T04:08:24
True
False
False
/api/public/snipt/104787/
drupal-7-load-block-view-in-a-template-file
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> <span class="nv">$block_to_load</span> <span class="o">=</span> <span class="nx">block_load</span><span class="p">(</span><span class="s1">&#39;views&#39;</span><span class="p">,</span> <span class="s1">&#39;your_block_name&#39;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a> <span class="nv">$output</span> <span class="o">=</span> <span class="nx">drupal_render</span><span class="p">(</span><span class="nx">_block_get_renderable_array</span><span class="p">(</span><span class="nx">_block_render_blocks</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$block_to_load</span><span class="p">))));</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">print</span> <span class="nv">$output</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
drupal7, php, tpl