snipt

Ctrl+h for KB shortcuts

PHP

Add block to node

1
2
3
4
5
6
7
<?php 
$block = block_load('module_name', 'block_name');      
$output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));        
print $output;

//module_name is the name of module that outputs the block, eg. webform
//block_name is the name of the block, you can find it out by hovering on configure link on block admin page, eg. client-block-19
https://snipt.net/embed/bb99c4abd1bb05857af62141291606e3/
/raw/bb99c4abd1bb05857af62141291606e3/
bb99c4abd1bb05857af62141291606e3
php
PHP
7
2019-06-25T02:53:18
True
False
False
/api/public/snipt/50141/
add-block-to-node
<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 class="nv">$block</span> <span class="o">=</span> <span class="nx">block_load</span><span class="p">(</span><span class="s1">&#39;module_name&#39;</span><span class="p">,</span> <span class="s1">&#39;block_name&#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><span id="L-6"><a name="L-6"></a><span class="c1">//module_name is the name of module that outputs the block, eg. webform</span> </span><span id="L-7"><a name="L-7"></a><span class="c1">//block_name is the name of the block, you can find it out by hovering on configure link on block admin page, eg. client-block-19</span> </span></pre></div> </td></tr></table>
block, drupal

PHP

Adding variables to Drupal.settings

<?php
drupal_add_js(array('muriqui' => array('theme' => path_to_theme())), 'setting');
https://snipt.net/embed/be294eb43a377c13a30de49f8d14a949/
/raw/be294eb43a377c13a30de49f8d14a949/
be294eb43a377c13a30de49f8d14a949
php
PHP
2
2019-06-24T17:59:36
True
False
False
/api/public/snipt/47436/
adding-variables-to-drupalsettings
<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="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="nx">drupal_add_js</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">&#39;muriqui&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;theme&#39;</span> <span class="o">=&gt;</span> <span class="nx">path_to_theme</span><span class="p">())),</span> <span class="s1">&#39;setting&#39;</span><span class="p">);</span> </span></pre></div> </td></tr></table>
drupal, javascript

JavaScript

Drupal 7 jQuery integration

1
2
3
4
5
6
7
(function ($) {
  Drupal.behaviors.MYMODULE = {
    attach: function(context, settings) {
      // Hier kann nun wie gewohnt jQuery-Code stehen.
    }
  };
})(jQuery);
https://snipt.net/embed/57c69c9b4e22e6c3be527d2110708957/
/raw/57c69c9b4e22e6c3be527d2110708957/
57c69c9b4e22e6c3be527d2110708957
js
JavaScript
7
2019-06-25T09:30:42
True
False
False
/api/public/snipt/47266/
drupal-7-jquery-integration
<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="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">$</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">Drupal</span><span class="p">.</span><span class="nx">behaviors</span><span class="p">.</span><span class="nx">MYMODULE</span> <span class="o">=</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">attach</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">context</span><span class="p">,</span> <span class="nx">settings</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="c1">// Hier kann nun wie gewohnt jQuery-Code stehen.</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">}</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">};</span> </span><span id="L-7"><a name="L-7"></a><span class="p">})(</span><span class="nx">jQuery</span><span class="p">);</span> </span></pre></div> </td></tr></table>
"drupal 7", drupal, jquery

Bash

Drush cron

drush cron -v
https://snipt.net/embed/2bba4c24cc9a888c96da07f38d91cf1b/
/raw/2bba4c24cc9a888c96da07f38d91cf1b/
2bba4c24cc9a888c96da07f38d91cf1b
bash
Bash
1
2019-06-11T10:54:26
True
False
False
/api/public/snipt/44213/
drush-cron
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>drush cron -v </span></pre></div> </td></tr></table>
bash, cron, drupal, drush