-
☆ A M B ☆
- 24,524 Posts
Permanently, or just temporarily?
Permanently, you’d need to do an update of the site_content table. Temporarily you can access the $modx->documentObject array.
My template includes:
<title>[*pagetitle*] | [(site_name)]</title>
I have a product details page that shows details of a specific product. The page title is "Product details", but I want to change the page title (html title tag) to the name of the specific product.
This doesn’t seem to do anything:
$modx->documentObject[’pagetitle’] = $productName;
And neither does this:
$o = &$modx->documentOutput; // get a reference of the output
$o = str_replace("<title>[*pagetitle*]","<title>$productName",$o);
(I guess the above would only work in a plugin - OnWebPagePrerender?)
The only way I can think of doing what I want is to change the template to
<title>[[myTitle]] | [(site_name)]</title>
Where myTitle snippet would return the document pagetitle most of the time, but for the product details page, would look up the product name. The main snippet in the page also looks up the product name - is there any way to avoid this duplication, or am I just being precious?
The product info is stored in a separate database, not in the MODx database.
Thanks I did realise that - I can get the name into $productName, but I just wanted to avoid getting the name from the db once for the html title tag, and again in the body of the page (ie querying the database twice for the same page). It’s not a biggie - I think I’ll do it that way. Thanks for the replies.
I couldn’t wait till tomorrow - changed the document’s title to [+productTitle+] and added $modx->setPlaceholder(’productTitle’, $productTitle); to the main snippet on the page - works beautifully! Thanks for all your help.