Is there a function, such as $this->redirect(), but for page title overriding?
Or any other way?
Thank you
Is there a function, such as $this->redirect(), but for page title overriding?
Or any other way?
Thank you
I forge my wisdom
Into an arc surrounding all.
I forge my heartbeat
To a dome all heavens wide
depends where youre doing it from i would think...just guessing
Code:global $objPage; $objPage->title = "something";
From template...
Nope, that doesn't work...
Tried title, mainTitle, mainPageTitle — nothing...
I forge my wisdom
Into an arc surrounding all.
I forge my heartbeat
To a dome all heavens wide
??????Code:$objPage->pageTitle
The same... Seems that this var overrides by Contao after template code is run...(
I forge my wisdom
Into an arc surrounding all.
I forge my heartbeat
To a dome all heavens wide
Like Ramjet said -- it depends on where that code is. If you're doing it from inside a template, it won't work, I think because the template is already compiled before your code has a chance to run.
I used what probably is a hacky way to do this (I'm sure there's a much better way). I made a custom module that used the 'outputFrontendTemplate' hook to intercept the template and use RegEx to manually replace the title. It looks something like this:
new folders:
/system/modules/z_customMetaTitle/
/system/modules/z_customMetaTitle/config/
new file:
/system/modules/z_customMetaTitle/config/config.php
new file:Code:$GLOBALS['TL_HOOKS']['outputFrontendTemplate'][] = array('customMetaTitle', 'updateCustomMetaTitle');
/system/modules/z_customMetaTitle/customMetaTitle.php
Not sure if this helps, but it does let you override the page title to whatever you want.Code:class customMetaTitle extends Frontend { public function updateCustomMetaTitle($strContent, $strTemplate) { return preg_replace( '/\<title\>.*<\\/title\>/', '<title>' . 'My Custom Meta Title Here' . '</title>', $strContent ); } }
Brian
Oh my!!
Medianomaly, thank ou so much, you've helped me with another problem, that I was bitting for a long time (this one)
And thanx for this hack )
I forge my wisdom
Into an arc surrounding all.
I forge my heartbeat
To a dome all heavens wide
Glad to help.
Someone may come by and tell us what a bad solution this is and how we should use some undocumented built-in Contao method to modify the title the proper way.
Until then, at least this works.
Brian
Seriosuly, this solution works!
[code=php:33zgoiqh]<span class="syntaxdefault">
</span><span class="syntaxkeyword">global*</span><span class="syntaxdefault">$objPage</span><span class="syntaxkeyword">;
</span><span class="syntaxdefault">$objPage</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">pageTitle*</span><span class="syntaxkeyword">=*</span><span class="syntaxstring">'asd'</span><span class="syntaxkeyword">;
*</span><span class="syntaxdefault"></span>[/code:33zgoiqh]
From a template, sure? I've tried — it didn't...
I forge my wisdom
Into an arc surrounding all.
I forge my heartbeat
To a dome all heavens wide
It's works, trust me. I've use this code in my projects. For example in Catalog module.Originally Posted by Terion
Marcin
http://www.contao.pl - Polish Support Site
http://forum.contao.pl - Polish Contao community forum
-----------------------
Need custom template? Feel free to contact me by e-mail marcin@contao.pl
make sure you use "pageTitle" and don't use it multiple times in multiple templates, cause only 1 template can override the title, otherwise the next one will override the previous one. You can also add description (same method), keywords (using a GLOBALS array), etc.
I've figured out why it didn't work.
It doesn't work if to use it in FE template.
If in a module template — everything is good
Thank you all
I forge my wisdom
Into an arc surrounding all.
I forge my heartbeat
To a dome all heavens wide
Yeah -- thanks all.
That's probably why it wasn't working for me either.
Brian
Bookmarks