Skip to content

Commit

Permalink
#364 - Add article template method to easily retrieve a single articl…
Browse files Browse the repository at this point in the history
…e by id, or alias
  • Loading branch information
johanjanssens committed Jun 18, 2020
1 parent cd2d47b commit 415edf8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions contrib/k2/template/function/article.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Joomlatools Pages
*
* @copyright Copyright (C) 2018 Timble CVBA. (http://www.timble.net)
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
* @link https://github.com/joomlatools/joomlatools-pages for the canonical source repository
*/

return function($id)
{
static $entities;

if(!isset($entities[$id]))
{
//Check if an alias exists
$id = $this->getObject('ext:k2.model.articles')->getAliases()->get($id, $id);

if(is_numeric($id)) {
$entities[$id] = $this->getObject('ext:k2.model.articles')->id($id)->fetch();
} else {
$entities[$id] = $this->getObject('ext:k2.model.articles')->slug($id)->fetch();
}
}

return $entities[$id];
};

0 comments on commit 415edf8

Please # to comment.