Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

PHP

PHP path arguments for block visibility in Drupal 7

1
2
3
4
5
6
7
8
<?php
global $user;
$uid = $user->uid; // Get the logged in user id
// If the path is 'mypath/myarg' the arg(0) is the 'mypath' and arg(1) is 'myarg'.
$show = (arg(0) == 'mypath') && (arg(1) == $uid); // It must both return TRUE

return $show;
?>
https://snipt.net/embed/e1421b507d61a3d3eacb1213dc44a459/
https://snipt.net/raw/e1421b507d61a3d3eacb1213dc44a459/
e1421b507d61a3d3eacb1213dc44a459
php
PHP
8
2016-12-09T02:36:40
True
False
False
Jul 23, 2013 at 05:15 PM
/api/public/snipt/69236/
php-path-arguments-for-block-visibility-in-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> <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="k">global</span> <span class="nv">$user</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">$uid</span> <span class="o">=</span> <span class="nv">$user</span><span class="o">-&gt;</span><span class="na">uid</span><span class="p">;</span> <span class="c1">// Get the logged in user id</span> </span><span id="L-4"><a name="L-4"></a><span class="c1">// If the path is &#39;mypath/myarg&#39; the arg(0) is the &#39;mypath&#39; and arg(1) is &#39;myarg&#39;.</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$show</span> <span class="o">=</span> <span class="p">(</span><span class="nx">arg</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;mypath&#39;</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="p">(</span><span class="nx">arg</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">==</span> <span class="nv">$uid</span><span class="p">);</span> <span class="c1">// It must both return TRUE</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a><span class="k">return</span> <span class="nv">$show</span><span class="p">;</span> </span><span id="L-8"><a name="L-8"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"drupal 7", block, php, visibility

PHP

Drupal 7: Import a custom block in a template

1
2
3
4
<?php
$block = module_invoke('block', 'block_view', '3'); // 3 is the block id
print render($block['content']);
?>
https://snipt.net/embed/d19ebe557a2369a6913bccf0fe52cbfa/
https://snipt.net/raw/d19ebe557a2369a6913bccf0fe52cbfa/
d19ebe557a2369a6913bccf0fe52cbfa
php
PHP
4
2016-12-02T21:34:50
True
False
True
Feb 27, 2013 at 11:56 AM
/api/public/snipt/56607/
drupal-7-import-a-custom-block-in-a-template
<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="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">module_invoke</span><span class="p">(</span><span class="s1">&#39;block&#39;</span><span class="p">,</span> <span class="s1">&#39;block_view&#39;</span><span class="p">,</span> <span class="s1">&#39;3&#39;</span><span class="p">);</span> <span class="c1">// 3 is the block id</span> </span><span id="L-3"><a name="L-3"></a><span class="k">print</span> <span class="nx">render</span><span class="p">(</span><span class="nv">$block</span><span class="p">[</span><span class="s1">&#39;content&#39;</span><span class="p">]);</span> </span><span id="L-4"><a name="L-4"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"drupal 7", block, template

Text only

.htaccess: Blocking access from everyone but one IP

1
2
3
order deny,allow 
deny from all 
allow from xxx.xxx.xxx.xxx
https://snipt.net/embed/f582420136e1d485d17ad7a038d82649/
https://snipt.net/raw/f582420136e1d485d17ad7a038d82649/
f582420136e1d485d17ad7a038d82649
text
Text only
3
2016-12-07T09:32:26
True
False
False
/api/public/snipt/53004/
htaccess-blocking-access-from-everyone-but-one-ip
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>order deny,allow </span><span id="L-2"><a name="L-2"></a>deny from all </span><span id="L-3"><a name="L-3"></a>allow from xxx.xxx.xxx.xxx </span></pre></div> </td></tr></table>
IP, block, htaccess

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/
https://snipt.net/raw/bb99c4abd1bb05857af62141291606e3/
bb99c4abd1bb05857af62141291606e3
php
PHP
7
2016-12-10T03:58:45
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

CSS

Crossbrowser inline-block property

1
2
3
4
5
6
#menu li {
	display:inline-block;

	zoom: 1;
	*display:inline;
}
https://snipt.net/embed/63e13543ee9b91c5869ff2a4c03acc24/
https://snipt.net/raw/63e13543ee9b91c5869ff2a4c03acc24/
63e13543ee9b91c5869ff2a4c03acc24
css
CSS
6
2016-12-10T15:35:54
True
False
False
/api/public/snipt/33507/
crossbrowser-inline-block-property
<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="nn">#menu</span> <span class="nt">li</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="nb">display</span><span class="o">:</span><span class="nb">inline</span><span class="o">-</span><span class="nb">block</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a> <span class="n">zoom</span><span class="o">:</span> <span class="m">1</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a> <span class="o">*</span><span class="nb">display</span><span class="o">:</span><span class="nb">inline</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
block, crossbrowser, css, display, fix, ie, inline
Copyrighted, illegal, or inappropriate content? Email [email protected].