12

I want to set up my template so it will display different layout depending on what component is being used on current page. How to check for this?

22

For Joomla 3.x

While the code from the other answer will work, JRequest is deprecated, therefore you should use the following:

$jinput = JFactory::getApplication()->input;
echo $jinput->get('option');

For example, if you are displaying an Article and use the above code, it will output com_content

9

For Joomla 2.5

We can check by getting the URL parameters, using the JRequest::getVar() method and check for the option parameter.

jimport( 'joomla.environment.request' );
echo JRequest::getVar('option', '')

JRequest API Documentation

  • 2
    JRequest::getVar() is deprecated. Use JFactory::getApplication()->input->get('option', '');. – Farahmand Aug 25 '14 at 19:04
1

Another approach is through the JRouter object:

JFactory::getApplication()->getRouter()->getVars()["option"]

Unsure if there is ever a practical difference between the JRouter value and the value returned through JInput.

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.