1

I created my own Joomla Library which holds a few utility functions and some views which should be shared with other extensions that need the same views.

Inside one extensions ("Redextension") view all i do is call:

JLoader::import('mylib.views.objects');

The objects view is just a regular view:

defined('_JEXEC') or die;
class RedextensionViewObjects extends JViewLegacy
{
    function display($tpl=null) {
...

The question is how would i go about abstracting the "Redextension" Prefix because that will of course not work if i use that view in another extension that is called "Blueextension". Same goes for Models. The extensions have the same DB structure and parts of the functionality, so it would be great if I could share that within a library.

1

A view is an extension asset. In plain Joomla library, there is no way to share a full view between extensions.

  • For instance, every extension install can have only one SQL script. To combine several installation SQL scripts, you have to write your own installer script.
  • In addition, to load a set of Models or Views from a different location, you have to add them in your extension with a call to the library initialization, several JLoader::import or JLoader:register.
  • JLayouts can help you to share presentation code. https://docs.joomla.org/J3.x:Sharing_layouts_across_views_or_extensions_with_JLayout

On the other hand, in FoF world (https://github.com/akeeba/fof), you can call a view between extensions or modules. For example:

$config = array(
                'option' => 'com_todo',
                'view' => 'tasks',
                'layout' => $layout,
                'input' => $input
);

F0FDispatcher::getTmpInstance('com_todo', 'tasks', $config)->dispatch();
  • I managed to share a view like this:JLoader::import('mylib.views.base'); JLoader::import('mylib.views.objects'); class RedextensionViewObjects extends MylibViewObjects { function display($tpl = null) { $this->addTemplatePath(JPATH_LIBRARIES .'/mylib/views/objects/'); parent::display($tpl); } } – Mike Mar 6 '15 at 11:27
  • I often use JLayouts in this case, I use the same layout in the component, its module and its plugin (for inserting content into Joomla article or K2 article). Here is the doc just in case someone looking for it docs.joomla.org/… – Hung Tran Mar 7 '15 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.