1

I am trying to put a module inside another component. According to https://www.joomlashack.com/blog/joomla-how-to/module-position-component/ I can put

<?php echo JHtml::_('content.prepare', '{loadposition myposition}'); ?>

in the PHP file in question.

I've tried this but it didn't work for me, this line of code simply doesn't output anything to my HTML. There is no error thrown either. So is this still technique still available? Or did I miss anything?

1
  • How can we progress this page so that it is not bumped by the system? Do you need a different/better answer? Do you want to edit your question to specify what you need? Commented Jun 21, 2021 at 7:47

2 Answers 2

1

I tried this before too. But there is no need to do a content.prepare because we can simply create a module position instead.

// Load the namespacing for Factory (the new way instead of JFactory)
use Joomla\CMS\Factory;

// Load the module position
<?php echo Factory::getApplication()->getDocument()->loadRenderer('modules')->render("logo"); ?>

In this instance the module position will be called "logo" but you can call it anything you want. In one case I used a subform to dynamically create module positions on the fly within another module.

0

@Eoin's snippet works perfectly other than it should be JFactory.

// Load the namespacing for Factory (the new way instead of JFactory)
use Joomla\CMS\Factory;

// Load the module position
<?php echo JFactory::getApplication()->getDocument()->loadRenderer('modules')->render("logo"); ?>
3
  • Thank you for contributing, please take our tour. Commented Sep 27, 2021 at 21:25
  • 4
    A helpful read on the deprecation of JFactory and how to call the factory class: joomla.stackexchange.com/a/24486/12352 Commented Sep 27, 2021 at 21:53
  • For Joomla 3 this should definitely be the way. Fair point.
    – Eoin
    Commented Jan 22 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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