Joomla 中的页面特定逻辑 [英] Page-specific logic in Joomla
问题描述
我试图在 Joomla 模板中启用 JavaScript,使其根据页面表现不同.特别是,我已经设置了 Key Reference 如出现成为我为此目的所能找到的最合适的值.不幸的是,我似乎无法在我的代码中访问它.我试过了:
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.
相关文章
- 特定页面中的 Joomla 加载脚本:这行得通,但对于我想在这里做的事情来说似乎有点矫枉过正.
- Joomla load script in a specific page: This would work, but seems like overkill for what I want to do here.
推荐答案
每个页面都可以给一个 别名.我们可以使用论坛代码来检索别名:
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;
}
然后我们可以将其注入到 Javascript 中:
We can then inject this into the Javascript:
var alias= '<?php echo getCurrentAlias(); ?>';
这篇关于Joomla 中的页面特定逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!