How to use custom component config parameter on the frontend?

Select your language

How to create custom form field for custom component Joomla 4

Problem: We have courses in the backend and for each course, we can set the image. The problem is that if there is no image, no image found display which may affect SEO and mess up design too, so we need to give a solution for this problem.


We will set a field of the type "media" in the component backend config.xml, 

In file administrator->components->com_lmstarbiats->config.xml


		<field name="courseimg" type="media" directory="" />


Later we will access this config field as parameter in frontend.

Next, In file components->com_lmstarbiats->tmpl->courses->default.php

// Import `ComponentHelper` class.
use Joomla\CMS\Component\ComponentHelper;

// Get all params of a specific component.
$params = ComponentHelper::getParams('com_lmstarbiats');

// To get the value of the param.
$courseimg_ = $params->get('courseimg');


I hope this will be a useful guide for you. Don't forget to explore my other site area(services, courses, blog) and join me on my tawasal for much more.