Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding javascript to head of Joomla website

I have gone through some Joomla tutorials and I am not understanding how Joomla works. I have never encountered something where every aspect of it evades me. I'm not asking for a free ride.. just where to go or a basic idea of how this works.

I simply need to add a Panoramio javascript into the <head></head> section of a joomla website. In Word Press I simply download the header.php template and code away.

It's so confusing understanding Joomla. I do know not to paste directly into an "Article" page so do I have to install some sort of extension or tool to even get this to work?

I read to edit the index.php in my templates but I can't even find that. Am I the only person that can't understand Joomla at all? Even the beginner documentation seems to assume I know their system. Thank you in advance.

like image 393
LITguy Avatar asked Feb 15 '13 20:02

LITguy


2 Answers

Be careful about which files you add code to. Editing core files like the index.php in the templates folder might not be the best solution. What if there is a template update? The file will get overridden. So just bare that in mind.

Before you add the script, it is good idea to get the name of current template:

$app = JFactory::getApplication();
$template = $app->getTemplate();

You can use the following to import a .js file the <head> tags:

$doc = JFactory::getDocument(); //only include if not already included
$doc->addScript(JUri::root() . 'templates/' . $template . '/file.js');

or you can add the Javascript there and then like so:

$doc = JFactory::getDocument();
$js = "
       //javascript goes here
      ";
$doc->addScriptDeclaration($js);

Hope this helps

like image 59
Lodder Avatar answered Sep 18 '22 11:09

Lodder


you can edit index.php file and other template files as css etc.

go to : Extensions->template manager

chose template TAB

Second from the left you see: "template name" Details and Files here you can edit any template file directly on your server.

Menu can change depending on Joomla version, but that's the general idea.

like image 29
Naomi Fridman Avatar answered Sep 16 '22 11:09

Naomi Fridman