I am trying to use Jlayout in a plugin I am writing and everything works fine except that the Language Constants in the layout file are not being replaced.

My call to render the layout is;

$layout = new JLayoutFile($layoutname, $layoutpath);
$body = $layout->render($data);

In my layout file I have:

        <th><?php echo Jtext::_('COM_MEMBERSHIPS_FIELD_MEMBERSHIP_LABEL'); ?></th>
        <td><?php echo $displayData['membership']; ?></td>

If I dump $body after the render I get:


The '911' is the data expected for the field membership but I am expecting:

Membership: 911

I have been chasing this problem for hours now and don't seem to be able to find anything that gives me any clues about what is going on.

What I can share is that the Constant is in the .ini file in both the site and admin language files as the constant is properly replaced in other Views.

My assumption is that for some reason the language files are not found in the Jlayout process, like I am missing a line or something that needs to include it, but I can't find any examples that show anything else is needed.


1 Answer 1


I've just checked a few things since responding. Please see below line break.

Are you calling the $this->loadLanguage($this->_name, [path/to/language/directory]); call in your plugin?

At a quick glance, I can see that you appear to have a typo in your Jtext::_() call. Try replacing it with JText::_() instead.

If this doesn't work: Have you switched on language debugging?

Will try checking it in plugin I'm working on, and post update accordingly.

** UPDATE: ** I can confirm that calling Jtext::_() or JText::_() result in my PLG_MYPLUGIN_CONSTANTS are translated.

So, I'd recommend checking that:

  1. You have both language files specified as sub-elements of the languages element of your extension's manifest file (.xml) with the following values:
  1. You are loading the language using the aforementioned $this->loadLanguage() method in your plugin's __construct() method
  2. You are successfully translating your plugin's constants
  • Thanks for your detailed response. I had to add a $this->loadLanguage('com_memberships'); line to the plugin to resolve the issue. With my 20/20 glasses on, and after doing a JFactory::getLanguage, it makes sense because the plugin was called from COM_ACME but the JLayout was trying to resolve CONSTANTS from COM_MEMBERSHIPS. Thanks again.
    – Irata
    Commented Feb 6, 2019 at 3:46
  • @JoomGuy Your joomla-guy-cardiff.uk site is still "down". I was hoping to cyberstalk you, but I don't have enough to go on. Commented Feb 6, 2019 at 5:29

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.