Search code examples
phpjoomlaarticle

Loading an article into a components template in Joomla


i would like to load an article into a components templates php code within the Joomla framework.

I can load modules in php, modules in articles, components in articles and and..but i never wanted to load an article into a components php.

Does anybody know of a code snippet for that?

Appreciate any help.


Solution

  • I would load the article model in your view like

    JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_content/models', 'ContentModel');
    $model = JModelLegacy::getInstance('Article', 'ContentModel', array('ignore_request' => true));
    $article = $model->getItem((int) $articleId);
    

    Now you can access all the fields which are available in the article like $item->fulltext or $item->introtext. Have a look at the article view to check out all the fancy stuff it does with the article before it displays it.