问题
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:
- You can create a "Hide Menu";
- Create the page link in this Menu;
- 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