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

PHP

Drupal 7: Display image style on node template

1
2
3
4
5
6
<?php $image_uri = $node->field_illustration['und'][0]['uri'] ?>
<?php $image_url_with_style = image_style_url('thumbnail', $image_uri) ?>

<a href="<?php print $node_url ?>">
    <img src="<?php echo $image_url_with_style ?>" />
</a>
https://snipt.net/embed/e4cf4a2322be14ca21b40c624ffd401d/
/raw/e4cf4a2322be14ca21b40c624ffd401d/
e4cf4a2322be14ca21b40c624ffd401d
php
PHP
6
2016-12-26T07:45:07
True
False
True
Feb 19, 2013 at 04:38 AM
/api/public/snipt/56009/
drupal-7-display-image-style-on-node-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> <a href="#L-5">5</a> <a href="#L-6">6</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 class="nv">$image_uri</span> <span class="o">=</span> <span class="nv">$node</span><span class="o">-&gt;</span><span class="na">field_illustration</span><span class="p">[</span><span class="s1">&#39;und&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="s1">&#39;uri&#39;</span><span class="p">]</span> <span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-2"><a name="L-2"></a><span class="cp">&lt;?php</span> <span class="nv">$image_url_with_style</span> <span class="o">=</span> <span class="nx">image_style_url</span><span class="p">(</span><span class="s1">&#39;thumbnail&#39;</span><span class="p">,</span> <span class="nv">$image_uri</span><span class="p">)</span> <span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="x">&lt;a href=&quot;</span><span class="cp">&lt;?php</span> <span class="k">print</span> <span class="nv">$node_url</span> <span class="cp">?&gt;</span><span class="x">&quot;&gt;</span> </span><span id="L-5"><a name="L-5"></a><span class="x"> &lt;img src=&quot;</span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$image_url_with_style</span> <span class="cp">?&gt;</span><span class="x">&quot; /&gt;</span> </span><span id="L-6"><a name="L-6"></a><span class="x">&lt;/a&gt;</span> </span></pre></div> </td></tr></table>
"drupal 7", "image style", template

PHP

Drupal 7 : access view panes argument in template

1
2
3
4
<?php

// In the view template you've override
var_dump($view->args) // will show you the list of args available 
https://snipt.net/embed/7a8155a64897580a9144836aa07f2894/
/raw/7a8155a64897580a9144836aa07f2894/
7a8155a64897580a9144836aa07f2894
php
PHP
4
2016-12-26T16:51:21
True
False
True
Jan 16, 2013 at 07:09 AM
/api/public/snipt/53830/
drupal-7-access-view-panes-argument-in-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><span id="L-3"><a name="L-3"></a><span class="c1">// In the view template you&#39;ve override</span> </span><span id="L-4"><a name="L-4"></a><span class="nb">var_dump</span><span class="p">(</span><span class="nv">$view</span><span class="o">-&gt;</span><span class="na">args</span><span class="p">)</span> <span class="c1">// will show you the list of args available </span> </span></pre></div> </td></tr></table>
"drupal 7", "view panes", argument, template