2

In my component under Joomla! 4.0, I have the following call which returns:

error JHtml componentname not found.

HTMLHelper::_(
    'componentname.link',
    'index.php?option=com_component&view=credits',
    Text::_('COM_COMPONENT_MYTEXT'),
    '',
    '',
    '',
    ''
);

I have a namespaced class called ComponentName under Component\Name\Libraries\Html\Html. How can I make HTMLHelper find the namespaced class of my component?

2 Answers 2

0

HTMLHelper needs to be told where to search for custom classes, try adding HTMLHelper->addIncludePath('YOUR PATH') with the path to your component.

If you want you could load libraries/src/HTML/HTMLHelper.php and look around after line 126. That's where it goes looking for the custom class information.

It looks like you are attempting to make an href link, is this the case?

2
  • I use namespaced class in my component which are autloaded by Joomla! so this method addIncludePath() can't work in my case and by the way it's a method deprecated May 3, 2021 at 20:23
  • I'm not sure HTMLHelper is the best function to use. What are actualy trying to get your override to do when it calls componentname.link?
    – mfleeson
    May 4, 2021 at 11:17
0

I have solved it by adding a class file under /site/src/Service/Html/Grid.php with the namespace Mycomponent\Forum\Site\Service\Html; in this class, I have some methods like published().

Then in the file /admin/src/Extension/MyComponent.php, I added the class into the boot method:

public function boot(ContainerInterface $container) 
{
    $this->getRegistry()->register('grid', new Grid($container->get(SiteApplication::class)));
}

Then I can call the method like:

HTMLHelper::_('grid.published', $row, $item->published, '', true);

Your Answer

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

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