snipt

Ctrl+h for KB shortcuts

PHP

Drupal 7: Import a custom block in a template

1
2
3
4
<?php
$block = module_invoke('block', 'block_view', '3'); // 3 is the block id
print render($block['content']);
?>
https://snipt.net/embed/d19ebe557a2369a6913bccf0fe52cbfa/
/raw/d19ebe557a2369a6913bccf0fe52cbfa/
d19ebe557a2369a6913bccf0fe52cbfa
php
PHP
4
2016-12-31T15:04:05
True
False
True
Feb 27, 2013 at 11:56 AM
/api/public/snipt/56607/
drupal-7-import-a-custom-block-in-a-template
<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></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</span> <span class="o">=</span> <span class="nx">module_invoke</span><span class="p">(</span><span class="s1">&#39;block&#39;</span><span class="p">,</span> <span class="s1">&#39;block_view&#39;</span><span class="p">,</span> <span class="s1">&#39;3&#39;</span><span class="p">);</span> <span class="c1">// 3 is the block id</span> </span><span id="L-3"><a name="L-3"></a><span class="k">print</span> <span class="nx">render</span><span class="p">(</span><span class="nv">$block</span><span class="p">[</span><span class="s1">&#39;content&#39;</span><span class="p">]);</span> </span><span id="L-4"><a name="L-4"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"drupal 7", block, template