Set page title in Joomla! 3 from a module

最后都变了- 提交于 2019-12-23 17:12:39

问题


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.

I tried using

$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.


回答1:


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.




回答2:


  1. You can create a "Hide Menu";
  2. Create the page link in this Menu;
  3. Change the page title in Menu item without any code line...



回答3:


the simplest way is to set a second var, set your own title and the next line should be like this:

$app->titleoverridden = true;

in components/com_content/view/article/view.html.php ~ Line 260 change:

$this->document->setTitle($title);

to

if(!$app->titleoverriden){
    $this->document->setTitle($title);
}

but notice, if you get an update it CAN BE overridden!



来源:https://stackoverflow.com/questions/31454079/set-page-title-in-joomla-3-from-a-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!