Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

PHP

Inject data into a module position

1
2
3
4
5
<?php
// Inject data from your component into the right module position
JFactory::getDocument()->setBuffer($data, 'modules', 'right');

// Note: Data will not be shown unless there are "real" modules present in position right
https://snipt.net/embed/130d081d59867fbbba5a542407fc5b69/
https://snipt.net/raw/130d081d59867fbbba5a542407fc5b69/
130d081d59867fbbba5a542407fc5b69
php
PHP
5
2016-12-09T22:56:13
True
False
False
Apr 01, 2014 at 11:55 AM
/api/public/snipt/126514/
inject-data-into-a-module-position-1
<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="c1">// Inject data from your component into the right module position</span> </span><span id="L-3"><a name="L-3"></a><span class="nx">JFactory</span><span class="o">::</span><span class="na">getDocument</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">setBuffer</span><span class="p">(</span><span class="nv">$data</span><span class="p">,</span> <span class="s1">&#39;modules&#39;</span><span class="p">,</span> <span class="s1">&#39;right&#39;</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="c1">// Note: Data will not be shown unless there are &quot;real&quot; modules present in position right</span> </span></pre></div> </td></tr></table>
joomla, module, position

Text only

Rewrite Xmap URL

1
2
3
4
5
6
RewriteCond %{REQUEST_URI} ^/es/sitemap.xml
RewriteRule .* /es/index.php?option=com_xmap&view=xml&tmpl=component&id=1
RewriteCond %{REQUEST_URI} ^/en/sitemap.xml
RewriteRule .* /en/index.php?option=com_xmap&view=xml&tmpl=component&id=2
RewriteCond %{REQUEST_URI} ^/pt/sitemap.xml
RewriteRule .* /pt/index.php?option=com_xmap&view=xml&tmpl=component&id=3
https://snipt.net/embed/29b62e0c11755e05065242cf9fcd3991/
https://snipt.net/raw/29b62e0c11755e05065242cf9fcd3991/
29b62e0c11755e05065242cf9fcd3991
text
Text only
6
2016-12-09T22:56:20
True
False
False
Apr 01, 2014 at 11:48 AM
/api/public/snipt/126512/
rewrite-xmap-url
<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>RewriteCond %{REQUEST_URI} ^/es/sitemap.xml </span><span id="L-2"><a name="L-2"></a>RewriteRule .* /es/index.php?option=com_xmap&amp;view=xml&amp;tmpl=component&amp;id=1 </span><span id="L-3"><a name="L-3"></a>RewriteCond %{REQUEST_URI} ^/en/sitemap.xml </span><span id="L-4"><a name="L-4"></a>RewriteRule .* /en/index.php?option=com_xmap&amp;view=xml&amp;tmpl=component&amp;id=2 </span><span id="L-5"><a name="L-5"></a>RewriteCond %{REQUEST_URI} ^/pt/sitemap.xml </span><span id="L-6"><a name="L-6"></a>RewriteRule .* /pt/index.php?option=com_xmap&amp;view=xml&amp;tmpl=component&amp;id=3 </span></pre></div> </td></tr></table>
htaccess, joomla, rewrite, sitemap, xmap

Text only

Remove HTML comments with ReReplacer

1
2
3
4
5
Removes all 
<!--.*?-->

Leaves conditional comments, i.e. <!--[if IE]>
<!--(?!\[).*?(?!<\])-->
https://snipt.net/embed/d2d5b8370adba9bf0da63435963bc70d/
https://snipt.net/raw/d2d5b8370adba9bf0da63435963bc70d/
d2d5b8370adba9bf0da63435963bc70d
text
Text only
5
2016-12-09T22:56:27
True
False
False
/api/public/snipt/118677/
remove-html-comments-with-rereplacer
<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>Removes all </span><span id="L-2"><a name="L-2"></a>&lt;!--.*?--&gt; </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a>Leaves conditional comments, i.e. &lt;!--[if IE]&gt; </span><span id="L-5"><a name="L-5"></a>&lt;!--(?!\[).*?(?!&lt;\])--&gt; </span></pre></div> </td></tr></table>
"html comments", joomla, reprelacer

PHP

Load Joomla data model from anywhere

1
2
3
4
5
6
7
8
<?php
/*http://www.corephp.com/blog/joomla-mvc-load-a-model-from-anywhere/#.T2XTvh1yx3I*/
 JLoader::import('joomla.application.component.model'); 
// file name, full path
JLoader::import( 'product', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'models' );

$productModel = JModel::getInstance( 'Product', 'VirtueMartModel' );
?>
https://snipt.net/embed/487b0cb6746318fe388e8372e85dcde5/
https://snipt.net/raw/487b0cb6746318fe388e8372e85dcde5/
487b0cb6746318fe388e8372e85dcde5
php
PHP
8
2016-12-06T00:52:07
True
False
False
Jan 28, 2014 at 08:12 AM
/api/public/snipt/109019/
load-joomla-data-model-from-anywhere
<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="cm">/*http://www.corephp.com/blog/joomla-mvc-load-a-model-from-anywhere/#.T2XTvh1yx3I*/</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">JLoader</span><span class="o">::</span><span class="na">import</span><span class="p">(</span><span class="s1">&#39;joomla.application.component.model&#39;</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="c1">// file name, full path</span> </span><span id="L-5"><a name="L-5"></a><span class="nx">JLoader</span><span class="o">::</span><span class="na">import</span><span class="p">(</span> <span class="s1">&#39;product&#39;</span><span class="p">,</span> <span class="nx">JPATH_ADMINISTRATOR</span> <span class="o">.</span> <span class="nx">DS</span> <span class="o">.</span> <span class="s1">&#39;components&#39;</span> <span class="o">.</span> <span class="nx">DS</span> <span class="o">.</span> <span class="s1">&#39;com_virtuemart&#39;</span> <span class="o">.</span> <span class="nx">DS</span> <span class="o">.</span> <span class="s1">&#39;models&#39;</span> <span class="p">);</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a><span class="nv">$productModel</span> <span class="o">=</span> <span class="nx">JModel</span><span class="o">::</span><span class="na">getInstance</span><span class="p">(</span> <span class="s1">&#39;Product&#39;</span><span class="p">,</span> <span class="s1">&#39;VirtueMartModel&#39;</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>
database, joomla, model

PHP

Joomla frontpage check - alternative version

1
2
3
4
5
6
7
8
<?/php
    // Frontpage check
$menu = $app->getMenu();
if($menu->getActive() == $menu->getDefault()) $isFrontpage = true; else $isFrontpage = false;

if($isFrontpage){
    // Do something
}
https://snipt.net/embed/5a569eaa8b4412162fd4ee0aa38a17b9/
https://snipt.net/raw/5a569eaa8b4412162fd4ee0aa38a17b9/
5a569eaa8b4412162fd4ee0aa38a17b9
php
PHP
8
2016-12-10T06:17:32
True
False
False
Dec 18, 2013 at 06:17 AM
/api/public/snipt/101270/
joomla-frontpage-check-alternative-version
<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;?</span><span class="o">/</span><span class="nx">php</span> </span><span id="L-2"><a name="L-2"></a> <span class="c1">// Frontpage check</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">$menu</span> <span class="o">=</span> <span class="nv">$app</span><span class="o">-&gt;</span><span class="na">getMenu</span><span class="p">();</span> </span><span id="L-4"><a name="L-4"></a><span class="k">if</span><span class="p">(</span><span class="nv">$menu</span><span class="o">-&gt;</span><span class="na">getActive</span><span class="p">()</span> <span class="o">==</span> <span class="nv">$menu</span><span class="o">-&gt;</span><span class="na">getDefault</span><span class="p">())</span> <span class="nv">$isFrontpage</span> <span class="o">=</span> <span class="k">true</span><span class="p">;</span> <span class="k">else</span> <span class="nv">$isFrontpage</span> <span class="o">=</span> <span class="k">false</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="k">if</span><span class="p">(</span><span class="nv">$isFrontpage</span><span class="p">){</span> </span><span id="L-7"><a name="L-7"></a> <span class="c1">// Do something</span> </span><span id="L-8"><a name="L-8"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
frontpage, joomla, php
Copyrighted, illegal, or inappropriate content? Email [email protected].