Categories > TinyButStrong general >

Changing page titles in Joomla

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: RobN
Date: 2010-10-28
Time: 01:35

Changing page titles in Joomla

Is there anyway of changing the page title in Joomla once data has been retrieved from a mergeblock/select?
By: Skrol29
Date: 2010-10-28
Time: 11:03

Re: Changing page titles in Joomla

Hi,

The TBS plugin for Joomla gives 3 hooks that are not yet documented, they can be used when the TBS article calls an external script using {tbs}script=...{/tbs}
$TBS->JoomlaParams
$TBS->JoomlaLimitstart
$TBS->JoomlaArticle

Thus you can change the title of the current article using:
$TBS->JoomlaArticle->title = 'new title';
By: RobN
Date: 2010-10-28
Time: 18:41

Re: Changing page titles in Joomla

Hi,

So if I want to set the title to something that has been retrieved from the MySQL database, can I pass that information into the script?

This is what I have so far:
{tbs}embedded{/tbs}
<!--TBS
$profile_id = $_GET['profile_id'];
$TBS->MergeBlock('m','mysql','SELECT url, summary, name, sport FROM users WHERE user_id = '.$profile_id);
$TBS->JoomlaArticle->title = 'Profile - '.$name;
-->

Do I need to do something slightly different to get the data for name to be usable by JoomlaArticle? Or am I using the wrong syntax?

Thanks for your help to this point.
By: Skrol29
Date: 2010-10-28
Time: 23:12

Re: Changing page titles in Joomla

Hi,

$name is never set in your code.
You can retrieve the name by doing this:
$info = $TBS->MergeBlock('m,*','mysql','SELECT url, summary, name, sport FROM users WHERE user_id = '.$profile_id);
$name = $info['name'];


And you should prevent your SQL from injection.
This can be done by replacing:
$profile_id = $_GET['profile_id'];
with:
$profile_id = intval($_GET['profile_id']);
By: RobN
Date: 2010-10-29
Time: 01:55

Re: Changing page titles in Joomla

Using $info seems to get me closer but still not quite there, if I do print_r($info) I get the following:
Array ( [1] => Array ( [url] => /images/rob3.jpg [summary] => Average guy who's gone native [name] => Rob [sport] => Football ) )
But using $info['name'] does not seem to return anything. What am I doing wrong?

The actual query I am running now is:
$info = $TBS->MergeBlock('m,*','mysql','SELECT url, summary, name, sport FROM users u, data d WHERE u.user_id = d.user_id AND d.user_id = '.$profile_id);
where url, summary, name and sport columns are in the data table.
By: Skrol29
Date: 2010-10-29
Time: 09:40

Re: Changing page titles in Joomla

Hi,

Ok, my mistake. It is not $info['name'] but $info[1]['name'].
This is because TBS returns an array of array of records. Your query returns only one records but there could be several.