Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Text only

Getting the path to a PODS Image/File Field and Displaying it if it's not empty

1
2
3
4
5
6
7
<?php
$map_pdf_url = $obj->field( 'map_pdf.guid', true );

if ( 0 < strlen( $map_pdf_url ) ) {
echo '<a href="' . $map_pdf_url . '">Download PDF</a>';
};
?>
https://snipt.net/embed/506a0b70cfbd87afa6ebc68b78d8040d/
https://snipt.net/raw/506a0b70cfbd87afa6ebc68b78d8040d/
506a0b70cfbd87afa6ebc68b78d8040d
text
Text only
7
2016-12-02T15:13:54
True
False
False
/api/public/snipt/60329/
getting-the-path-to-a-pods-imagefile-field-and-displaying-it-if-its-not-empty
<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>&lt;?php </span><span id="L-2"><a name="L-2"></a>$map_pdf_url = $obj-&gt;field( &#39;map_pdf.guid&#39;, true ); </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a>if ( 0 &lt; strlen( $map_pdf_url ) ) { </span><span id="L-5"><a name="L-5"></a>echo &#39;&lt;a href=&quot;&#39; . $map_pdf_url . &#39;&quot;&gt;Download PDF&lt;/a&gt;&#39;; </span><span id="L-6"><a name="L-6"></a>}; </span><span id="L-7"><a name="L-7"></a>?&gt; </span></pre></div> </td></tr></table>
conditional, guid, if, image, php, pods, template

PHP

if PHP conditional

1
2
3
4
if($condicion)
{}
else
{}
https://snipt.net/embed/b79a7ce22990d2c5404bb1b4c3ef42b0/
https://snipt.net/raw/b79a7ce22990d2c5404bb1b4c3ef42b0/
b79a7ce22990d2c5404bb1b4c3ef42b0
php
PHP
4
2016-12-02T16:57:14
True
False
False
/api/public/snipt/42152/
if-php-conditional
<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">if($condicion)</span> </span><span id="L-2"><a name="L-2"></a><span class="x">{}</span> </span><span id="L-3"><a name="L-3"></a><span class="x">else</span> </span><span id="L-4"><a name="L-4"></a><span class="x">{}</span> </span></pre></div> </td></tr></table>
condicion, conditional, if, php

JavaScript+Smarty

javascript short test

if (var == 'valueone' || var == 'valuetwo') {...}
if (({valueone:1,valuetwo:1})[var]) {...}
https://snipt.net/embed/9076cf85567e31affc3daee9431b08e2/
https://snipt.net/raw/9076cf85567e31affc3daee9431b08e2/
9076cf85567e31affc3daee9431b08e2
js+smarty
JavaScript+Smarty
3
2016-12-02T16:57:16
True
False
False
/api/public/snipt/34714/
javascript-short-test
<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="k">if</span> <span class="p">(</span><span class="kd">var</span> <span class="o">==</span> <span class="s1">&#39;valueone&#39;</span> <span class="o">||</span> <span class="kd">var</span> <span class="o">==</span> <span class="s1">&#39;valuetwo&#39;</span><span class="p">)</span> <span class="cp">{</span><span class="o">...</span><span class="cp">}</span> </span><span id="L-2"><a name="L-2"></a><span class="k">if</span> <span class="p">((</span><span class="cp">{</span><span class="nf">valueone</span><span class="o">:</span><span class="m">1</span><span class="o">,</span><span class="na">valuetwo</span><span class="o">:</span><span class="m">1</span><span class="cp">}</span><span class="p">)[</span><span class="kd">var</span><span class="p">])</span> <span class="cp">{</span><span class="o">...</span><span class="cp">}</span> </span></pre></div> </td></tr></table>
if, shortcut

PHP

if else cascade alternative - switch hack

1
2
3
4
5
<?php
switch (true) {
  case test1==test2: ... break;
  case x1 > 14: ... break;
}
https://snipt.net/embed/5aca48442003c24db971af7e0bb5b3ac/
https://snipt.net/raw/5aca48442003c24db971af7e0bb5b3ac/
5aca48442003c24db971af7e0bb5b3ac
php
PHP
5
2016-12-02T16:33:03
True
False
False
/api/public/snipt/34713/
if-else-cascade-alternative-switch-hack
<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></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">switch</span> <span class="p">(</span><span class="k">true</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">case</span> <span class="nx">test1</span><span class="o">==</span><span class="nx">test2</span><span class="o">:</span> <span class="o">...</span> <span class="k">break</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">case</span> <span class="nx">x1</span> <span class="o">&gt;</span> <span class="mi">14</span><span class="o">:</span> <span class="o">...</span> <span class="k">break</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
cascade, else, if, ifelse, switch
Copyrighted, illegal, or inappropriate content? Email [email protected].