snipt

Ctrl+h for KB shortcuts

PHP

Render a content field inside a Node Template. Correct syntax for a field added to a node.

// render a content field inside a Node Template
print render($content['field_NAME_OF_FIELD']);
https://snipt.net/embed/32062154ff962442643fb7469e7a44e7/
/raw/32062154ff962442643fb7469e7a44e7/
32062154ff962442643fb7469e7a44e7
php
PHP
3
2019-06-26T05:40:56
True
False
False
/api/public/snipt/35623/
render-a-content-field-inside-a-node-template-correct-syntax-for-a-field-added-to-a-node
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</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">// render a content field inside a Node Template</span> </span><span id="L-2"><a name="L-2"></a><span class="x">print render($content[&#39;field_NAME_OF_FIELD&#39;]);</span> </span></pre></div> </td></tr></table>
"drupal 7", "node template", "node theme"

PHP

providing node templates in a module directory

1
2
3
4
5
6
7
<?php

function mymodule_theme_registry_alter(&$theme_registry) {
  $theme_hook = 'node';
  $modulepath = drupal_get_path('module', 'mymodule');
  array_unshift($theme_registry[$theme_hook]['theme paths'], $modulepath);
}
https://snipt.net/embed/ded0a5f2411a2d6a83824a3d7f70a17d/
/raw/ded0a5f2411a2d6a83824a3d7f70a17d/
ded0a5f2411a2d6a83824a3d7f70a17d
php
PHP
8
2019-07-13T22:07:06
True
False
False
/api/public/snipt/72/
providing-node-templates-in-a-module-directory
<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></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="k">function</span> <span class="nf">mymodule_theme_registry_alter</span><span class="p">(</span><span class="o">&amp;</span><span class="nv">$theme_registry</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="nv">$theme_hook</span> <span class="o">=</span> <span class="s1">&#39;node&#39;</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a> <span class="nv">$modulepath</span> <span class="o">=</span> <span class="nx">drupal_get_path</span><span class="p">(</span><span class="s1">&#39;module&#39;</span><span class="p">,</span> <span class="s1">&#39;mymodule&#39;</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a> <span class="nb">array_unshift</span><span class="p">(</span><span class="nv">$theme_registry</span><span class="p">[</span><span class="nv">$theme_hook</span><span class="p">][</span><span class="s1">&#39;theme paths&#39;</span><span class="p">],</span> <span class="nv">$modulepath</span><span class="p">);</span> </span><span id="L-7"><a name="L-7"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
"node template", "theme registry", drupal