在Joomla中设置页面标题! 3个来自模块 [英] Set page title in Joomla! 3 from a module
问题描述
我有一个现有模块,可以使用{loadposition custom_position}从文章中显示.文章链接到菜单项.我希望能够通过此模块设置自定义页面标题,从而覆盖菜单项设置的页面标题.
I have an existing module, which I display from an article by using {loadposition custom_position}. The article is linked to a menu item. I want to be able to set a customized page title from this module, overwriting the page title set by the menu item.
我尝试使用
$document = JFactory::getDocument();
$document->setTitle('Set your title here');
但是它不会设置页面标题.
But it does not set the page title.
是否可以从模块中设置页面标题,还是只能在组件中完成页面标题.
Is it possible to set the page title from within a module, or can it only be done within a component.
推荐答案
您编写的代码是正确的,但是也许其他模块/插件在更改标题后也正在更改标题.
The code you wrote is correct, but maybe other modules / plugins are changing the title after you change it.
您可能希望在设置标题后立即回显标题,例如
You may want to echo the title immediately after you set it, e.g.
$document = JFactory::getDocument();
$document->setTitle('Set your title here');
echo "<h1>" . JFactory::getDocument()->getTitle() . "</h1>";
如果这是正确的,则需要寻找其他模块/插件来稍后对其进行更改.
If that is correct, you need to look for other modules / plugins that change it later.
这篇关于在Joomla中设置页面标题! 3个来自模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!