2
votes

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');
?>
1
Where do you want to display the component? In an article? Could you provide more context?itoctopus
@itoctopus Directly in the template. Displaying it in an article would be fine as well, though, see the edit.Alex
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

1 Answers

2
votes

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.