Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This would be really simple in your theme, e.g. node-foo.tpl.php for the content-type foo, that has a field "video"</p> <pre><code>&lt;?php if(!empty($field_video[0]['view'])): ?&gt; &lt;div class="block video"&gt; &lt;?php print $field_video[0]['view'] ?&gt; &lt;/div&gt; &lt;?php print $field_some_other[0]['view'] ?&gt; &lt;?php print $field_the_other_one[0]['view'] ?&gt; &lt;?php endif; ?&gt; </code></pre> <p>Some notes on style and best practices: </p> <p>I prefer the if/endif in templates, others prefer the if() {}. Technically little difference, I think elseif; is more readable in HTML. </p> <p>Technically it is not correct to simply print a value, but one should use drupal_render(). I personally still prefer print, because of its transparancy and simplicity. Drupal_render(), however, registers what it has "rendered" and allows you to drupal_render($node) at the end, to render all unrendered fields; very usefull if you decide to add fields later on, whithout having to change the entire template every time you do so. Drupal_render is not available in the tpl.php, but in the preprocessing: as sayd, a lot less transparent and slightly more complex. </p> <p>Dont! Ever! print the $field_foo[0]['value'], always the ['view'] part: the first is unescaped and may (will!) contain XSS injections and the likes. </p> <p>The strange nested array ($field_foo[0]['value']) is a result of the multiple-fields option in Drupal. A better way would be to always iterate over each field and never just render, hardcoded, the first ([0]) item. However, for reasons of readability, simplicity and transparancy, I prefer to hardcode the indexes in my template. Others (rightfully) disagree with me on this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload