2

Is it possible to display a view of a component without iframe and plugin? (That is to say, if possible with a few lines of PHP and maybe SQL queries?)

EDIT: To be more clear: I'd like to do it directly in the PHP-Template! (Would be fine to do it in an article as well, as I have written a PHP-function showArticle(mixed $ident))

(I'm using Joomla 3.5)

I'd like to do something like

<jdoc:include type="component" view="example" name="position-x" />

or

<?php
    show_component('component-name', 'view-name');
?>
Alex
  • 751
  • 1
  • 6
  • 34
  • Where do you want to display the component? In an article? Could you provide more context? – itoctopus May 25 '16 at 14:11
  • @itoctopus Directly in the template. Displaying it in an article would be fine as well, though, see the edit. – Alex May 25 '16 at 14:28
  • It's not really designed to load more than one type="component" because of architectural design of the legacy MVC (a lot more is possible if you use the newer). That said what you want to do is to use a plugin, which is the joomla way of allowing you to use "a few lines of php" and possibly use a module for the layout. I'm not sure but you could also possibly use a JLayout and have it render the component view to a string of html, then display the string. – Elin May 28 '16 at 02:28

1 Answers1

2

you can use this component http://extensions.joomla.org/extension/components-anywhere Install the plugin and enable it. Then you can call the component this way {component url/of/the/component}

{component index.php?component=com_example&form=1}

Try to use non-sef urls in the url but sef url will still work.

There is another way to achieve this by calling the model into your controller file this way

JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_example/models', 'ExampleModel');

What this does is it searches the model class starting with ExampleModel in the folder specified. here you can eneter just a path string or array of the directories as the first parameter. Next you have to call the method inside the views file this way

$exmodel = JModelLegacy::getInstance('Something', 'ExampleModel', array('ignore_request' => true));

So here you create an instance of the class object which can be used to get the items from the model this way

$items = $exmodel->getitem();
$this->assignRef('items', $items);

next you can copy the default.php file in the tmpl folder of that component and place it anywhere you like inside your layout file. Basically instead of copying the entire component you are calling the model and getting the data which you can use in your layouts.

Amit Ray
  • 3,445
  • 2
  • 19
  • 35
  • Thanks for this answer, but as specified in my question I'd rather not use a plugin, but instead would like to have just a few lines of PHP... terribly annoying that there does not seem to be any easy solution for this... – Alex May 25 '16 at 22:30
  • he told you how to do with "just a few lines of PHP"!!! read carefully what he writes above! –  May 26 '16 at 13:49
  • @trajo I thought Joomla is also made with PHP so I wrote this code. May be his question is a bit ambiguous – Amit Ray May 26 '16 at 14:59
  • i dont mean you. youre answer is totally correct. he is asking for "a few lines of php" and you serve...all good ;) –  May 27 '16 at 13:24