$this->getThemePath()

Permalink
HI

Not sure why the following does not work, please can anyone help

global $c;
if (!$c->isEditMode()) {
   echo '<script src="' . $this->getThemePath() . '/js/mycode.js></script>';
}

Responsive
 
mkly replied on at Permalink Reply
mkly
Any chance you could be a bit more specific about where you are using that code snippet. The fact that you are using
global $c;

Makes me feel like you may not not be in either the Block View(view.php or a block) or a Page Type View(default.php, right_sidebar.php etc).

If you are getting an error like
Call to undefined method...

Then you may be in a the controller or somewhere else.

Beyond that, giving some additional information may help, as that doesn't look incorrect as it stands to me.

EDIT: @noXstyle for the win.
noXstyle replied on at Permalink Reply
noXstyle
True.

Also closing the src attribute helps to load the script.
Responsive replied on at Permalink Reply
Responsive
sorry should have given more details ...

trying to load the .js when a user is NOT logged in and placing the following code (changed it) into the header.php.

<?php
global $u; 
if(!$u->isLoggedIn()) { 
 echo ('<script src="' . $this->getThemePath() . '/js/mycode.js></script>'); 
 }
?>


The page does not load and I think I am missing some closing statement somewhere.
thanks
mkly replied on at Permalink Best Answer Reply
mkly
Indeed @noXstyle was correct in their statement. You are missing a closing quote to src

Try this instead
// Note the closing quote after mycode.js
echo ('<script src="' . $this->getThemePath() . '/js/mycode.js"></script>');
Responsive replied on at Permalink Reply
Responsive
Mnkly, thank you it worked

also thanks to noXstyle for the help.