Unable to change dynamic URL page title Topic is solved

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
vicn1222
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 128
Joined: Fri Jul 02, 2021 10:34 pm

Unable to change dynamic URL page title

Post by vicn1222 » Mon Aug 16, 2021 4:53 am

Hi,

I am building a dynamic page using php embedded by sourcer as shown below. I can't change the page title. I found the setTitle is overridden by components/com_content/views/article/view.html.php at line 288, which is called after my code.

Can anyone please show the correct way to set the title? Thank you.

Code: Select all

{source}
<?php

....
$document = JFactory::getDocument();
$document->setTitle( "My page title" );

?>
{/source}
Last edited by imanickam on Mon Aug 16, 2021 9:00 am, edited 1 time in total.
Reason: Moved topic » from General Questions/New to Joomla! 3.x to Joomla! 3.x Coding

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 44083
Joined: Sat Apr 05, 2008 9:58 pm

Re: Unable to change dynamic URL page title

Post by Webdongle » Mon Aug 16, 2021 9:07 am

The Browser Page Title can be defined in globally in global config or individually in a Menu Items 'Browser Page Title' field.
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".

vicn1222
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 128
Joined: Fri Jul 02, 2021 10:34 pm

Re: Unable to change dynamic URL page title

Post by vicn1222 » Mon Aug 16, 2021 2:06 pm

Webdongle wrote:
Mon Aug 16, 2021 9:07 am
The Browser Page Title can be defined in globally in global config or individually in a Menu Items 'Browser Page Title' field.
Hi,

Thank you for your reply.

Could you please give more details on this?

Here is what I do: I create an article (article id=3) without menu (I did try to create a hidden menu for this article, same error). This article is to show dynamic content. In .htaccess I do following re-write:

Code: Select all


Rewriterule ^directory/(.*).htm /index.php?option=com_content&view=article&id=3&q=$1 [NC,L]

With that I can create URLs like

https://www.mydomain.com/directory/xyz.htm
https://www.mydomain.com/directory/abc.htm
https://www.mydomain.com/directory/123.htm

All above URLs will go to that article, then I get the "q" string (in the above examples, I will get xyz, abc, 123, etc), and create dynamic content. I then need to set the related title, such as "xyz...", "abc...", "123...", etc.

To set the title, I do

Code: Select all

<?php

$document = JFactory::getDocument();
$document->setTitle( "My Page Title" );

$input = $_GET[ 'q' ];
// create dynamic content here

?>

However, $document->setTitle( ... ) is overridden later by components/com_content/views/article/view.html.php at line 288. So all dynamic URLs have the same browser title, which is the initial title when I create the article.

vicn1222
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 128
Joined: Fri Jul 02, 2021 10:34 pm

Re: Unable to change dynamic URL page title

Post by vicn1222 » Mon Aug 16, 2021 7:17 pm

I solved it by creating a hidden menu for that. Thank you.


Locked

Return to “Joomla! 3.x Coding”