17

I'm creating a new template for my joomla website and I've replaced joomla's native Mootools with jQuery and I'm converting all moo codes to jQuery ones.

Somehow many of codes like the ones in joomla libraries are written for both admin and frontend area, and if I replace them with jquery codes, admin section won't work properly. I wanna know if there's a way to determine if we are in admin section of site or not, so I can use javascript codes based on this condition.

Farid Rn
  • 3,167
  • 5
  • 39
  • 66

2 Answers2

36

It seems to work in Joomla 1.5, Joomla 2.x and 3.x

$app = JFactory::getApplication();
if ($app->isSite())  echo 'Client is site';
if ($app->isAdmin()) echo 'Client is administrator';
fmt
  • 3
  • 4
Shaz
  • 2,647
  • 2
  • 35
  • 45
5

For Joomla 4.0 should be

$app = Joomla\CMS\Factory::getApplication();
if ($app->getName() == 'administrator')   //since   3.2
    echo 'Client is administrator';
bato3
  • 2,695
  • 1
  • 18
  • 26
  • I notice in the code, that before 4,0 getApplication()->isAdmin() would do the job, but from 4.0, it is deprecated and isClient('administrator') is advised. isClient is valid from 3.7.0 onwards. – Mark Bradley Feb 22 '21 at 18:10