snipt

Ctrl+h for KB shortcuts

PHP

Drupal views: override template (tpl.php) from module

// More details at https://drupal.org/node/627378

/**
 * Implementation of hook_theme().
 */
function MYMODULE_theme() {
  return array(
    'views_view_field__VIEW_NAME__FIELD_NAME' => array(
      'arguments' => array('view' => NULL, 'field' => NULL, 'row' => NULL),
      'template' => 'views-view-field--VIEW-NAME--FIELD-NAME',
      'original hook' => 'views_view_field',
      'path' => drupal_get_path('module', 'MYMODULE') . '/MY_THEMES_PATH',
    ),
  );
}
https://snipt.net/embed/3f0a3b735554d2710d02060ad962aa75/
/raw/3f0a3b735554d2710d02060ad962aa75/
3f0a3b735554d2710d02060ad962aa75
php
PHP
15
2019-06-19T20:48:41
True
False
False
Dec 30, 2013 at 10:05 AM
/api/public/snipt/103047/
drupal-views-override-template-tplphp-from-module
<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> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a> <a href="#L-11">11</a> <a href="#L-12">12</a> <a href="#L-13">13</a> <a href="#L-14">14</a> <a href="#L-15">15</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x">// More details at https://drupal.org/node/627378</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="x">/**</span> </span><span id="L-4"><a name="L-4"></a><span class="x"> * Implementation of hook_theme().</span> </span><span id="L-5"><a name="L-5"></a><span class="x"> */</span> </span><span id="L-6"><a name="L-6"></a><span class="x">function MYMODULE_theme() {</span> </span><span id="L-7"><a name="L-7"></a><span class="x">  return array(</span> </span><span id="L-8"><a name="L-8"></a><span class="x">    &#39;views_view_field__VIEW_NAME__FIELD_NAME&#39; =&gt; array(</span> </span><span id="L-9"><a name="L-9"></a><span class="x">      &#39;arguments&#39; =&gt; array(&#39;view&#39; =&gt; NULL, &#39;field&#39; =&gt; NULL, &#39;row&#39; =&gt; NULL),</span> </span><span id="L-10"><a name="L-10"></a><span class="x">      &#39;template&#39; =&gt; &#39;views-view-field--VIEW-NAME--FIELD-NAME&#39;,</span> </span><span id="L-11"><a name="L-11"></a><span class="x">      &#39;original hook&#39; =&gt; &#39;views_view_field&#39;,</span> </span><span id="L-12"><a name="L-12"></a><span class="x">      &#39;path&#39; =&gt; drupal_get_path(&#39;module&#39;, &#39;MYMODULE&#39;) . &#39;/MY_THEMES_PATH&#39;,</span> </span><span id="L-13"><a name="L-13"></a><span class="x">    ),</span> </span><span id="L-14"><a name="L-14"></a><span class="x">  );</span> </span><span id="L-15"><a name="L-15"></a><span class="x">}</span> </span></pre></div> </td></tr></table>
drupal, hook_theme, override, templates, tpl, views