tags:

views:

58

answers:

2

I am trying to enable JavaScript in a Joomla template to behave differently depending on the page. In particular, I have set the Key Reference as that appears to be the most appropriate value I could find for this purpose. Unfortunately, I can't seem to access it in my code. I tried:

$this->params->get("keyref")

and a few other variations, but they simply returned a blank. How can I retrieve this value or is there a better way of writing page specific logic.

Related Articles

+1  A: 

I'm not aware of keyref, but I would solve it by using the class suffix parameter you can set for each menu entry.see I would use a space in front of this suffix. With javascript you can then try to read this classname (suffix without the space) on each page.

getElementsByClassName("mysuffix");

for example

If this returns multiple objects, you know on which page you are. Will that help you?

hsmit
See the [documentation on keyref](http://docs.joomla.org/Screen.content.edit.15#Parameters_-_Advanced)
Casebash
Thanks, I don't think that this is the best solution for this problem, but being aware of that is useful
Casebash
+1  A: 

Each page can be given an alias. We can retrieve the alias using code from the forum:

function getCurrentAlias()
{
   $menu   = &JSite::getMenu();
   $active   = $menu->getActive();
   return $active->alias;
}

We can then inject this into the Javascript:

var alias= '<?php echo getCurrentAlias(); ?>';
Casebash