Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

PHP

Print a Block in a Template file

1
2
3
4
5
6
7
8
<?php
			$block = block_load('views', 'user_content-block');      
			$output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));        
			print $output; 
		?>
		
		
		<?php print views_embed_view('user_content', 'block', $user->uid); ?>
https://snipt.net/embed/3584bab7e666f1ffc7016f93e1294aa3/
https://snipt.net/raw/3584bab7e666f1ffc7016f93e1294aa3/
3584bab7e666f1ffc7016f93e1294aa3
php
PHP
8
2016-11-25T11:53:10
True
False
False
Aug 13, 2013 at 04:59 PM
/api/public/snipt/73995/
print-a-block-in-a-template-file
<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></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">block_load</span><span class="p">(</span><span class="s1">&#39;views&#39;</span><span class="p">,</span> <span class="s1">&#39;user_content-block&#39;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a> <span class="nv">$output</span> <span class="o">=</span> <span class="nx">drupal_render</span><span class="p">(</span><span class="nx">_block_get_renderable_array</span><span class="p">(</span><span class="nx">_block_render_blocks</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$block</span><span class="p">))));</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">print</span> <span class="nv">$output</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a> <span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-6"><a name="L-6"></a><span class="x"> </span> </span><span id="L-7"><a name="L-7"></a><span class="x"> </span> </span><span id="L-8"><a name="L-8"></a><span class="x"> </span><span class="cp">&lt;?php</span> <span class="k">print</span> <span class="nx">views_embed_view</span><span class="p">(</span><span class="s1">&#39;user_content&#39;</span><span class="p">,</span> <span class="s1">&#39;block&#39;</span><span class="p">,</span> <span class="nv">$user</span><span class="o">-&gt;</span><span class="na">uid</span><span class="p">);</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"Drupal 7", "print block", tpl.php

HTML+PHP

Drupal 7 - Theming Views Fields

1
2
3
4
5
6
<div class="title">
  <?php print $fields["title"]->content; ?>
</div>
<div class="field_flowers_availability">
  <?php print $fields["field_flowers_availability"]->content; ?>
</div>
https://snipt.net/embed/70c849f3c93130a615f63d9f91bbe5b7/
https://snipt.net/raw/70c849f3c93130a615f63d9f91bbe5b7/
70c849f3c93130a615f63d9f91bbe5b7
html+php
HTML+PHP
6
2016-11-16T00:44:32
True
False
False
Feb 21, 2013 at 10:11 AM
/api/public/snipt/51500/
drupal-7-theming-views-fields
<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="p">&lt;</span><span class="nt">div</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;title&quot;</span><span class="p">&gt;</span> </span><span id="L-2"><a name="L-2"></a> <span class="cp">&lt;?php</span> <span class="k">print</span> <span class="nv">$fields</span><span class="p">[</span><span class="s2">&quot;title&quot;</span><span class="p">]</span><span class="o">-&gt;</span><span class="na">content</span><span class="p">;</span> <span class="cp">?&gt;</span> </span><span id="L-3"><a name="L-3"></a><span class="p">&lt;/</span><span class="nt">div</span><span class="p">&gt;</span> </span><span id="L-4"><a name="L-4"></a><span class="p">&lt;</span><span class="nt">div</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;field_flowers_availability&quot;</span><span class="p">&gt;</span> </span><span id="L-5"><a name="L-5"></a> <span class="cp">&lt;?php</span> <span class="k">print</span> <span class="nv">$fields</span><span class="p">[</span><span class="s2">&quot;field_flowers_availability&quot;</span><span class="p">]</span><span class="o">-&gt;</span><span class="na">content</span><span class="p">;</span> <span class="cp">?&gt;</span> </span><span id="L-6"><a name="L-6"></a><span class="p">&lt;/</span><span class="nt">div</span><span class="p">&gt;</span> </span></pre></div> </td></tr></table>
"Drupal 7", Theming, Views

PHP

taxonomy_node_get_terms_by_vocabulary Drupal 7

1
2
3
4
function _taxonomy_node_get_terms_by_vocabulary($node, $vid, $key = 'tid') {
  $result = db_query('SELECT t.tid, t.* FROM {taxonomy_term_data} t INNER JOIN {taxonomy_index} r ON r.tid = t.tid WHERE t.vid = :vid AND r.nid = :node_nid ORDER BY weight', array(':vid' => $vid, ':node_nid' => $node->nid));
  return $result->fetchAll();
}
https://snipt.net/embed/a03fcffb98069194c90569ce3092c0ce/
https://snipt.net/raw/a03fcffb98069194c90569ce3092c0ce/
a03fcffb98069194c90569ce3092c0ce
php
PHP
4
2016-12-09T12:03:49
True
False
False
/api/public/snipt/39576/
taxonomy_node_get_terms_by_vocabulary-drupal-7
<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="x">function _taxonomy_node_get_terms_by_vocabulary($node, $vid, $key = &#39;tid&#39;) {</span> </span><span id="L-2"><a name="L-2"></a><span class="x"> $result = db_query(&#39;SELECT t.tid, t.* FROM {taxonomy_term_data} t INNER JOIN {taxonomy_index} r ON r.tid = t.tid WHERE t.vid = :vid AND r.nid = :node_nid ORDER BY weight&#39;, array(&#39;:vid&#39; =&gt; $vid, &#39;:node_nid&#39; =&gt; $node-&gt;nid));</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> return $result-&gt;fetchAll();</span> </span><span id="L-4"><a name="L-4"></a><span class="x">}</span> </span></pre></div> </td></tr></table>
"Drupal 7", drupal
Copyrighted, illegal, or inappropriate content? Email [email protected].