Results 1 to 14 of 14

Thread: How to override page title?

  1. #1
    User
    Join Date
    04-05-10.
    Location
    Ukraine, Kiev
    Posts
    47

    Default How to override page title?

    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

  2. #2
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: How to override page title?

    depends where youre doing it from i would think...just guessing
    Code:
    global $objPage;
    $objPage->title = "something";

  3. #3
    User
    Join Date
    04-05-10.
    Location
    Ukraine, Kiev
    Posts
    47

    Default Re: How to override page title?

    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

  4. #4
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: How to override page title?

    Code:
    $objPage->pageTitle
    ??????

  5. #5
    User
    Join Date
    04-05-10.
    Location
    Ukraine, Kiev
    Posts
    47

    Default Re: How to override page title?

    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

  6. #6
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: How to override page title?

    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
    Code:
    $GLOBALS['TL_HOOKS']['outputFrontendTemplate'][] = array('customMetaTitle', 'updateCustomMetaTitle');
    new file:
    /system/modules/z_customMetaTitle/customMetaTitle.php
    Code:
    class customMetaTitle extends Frontend
    {
    	public function updateCustomMetaTitle($strContent, $strTemplate)
    	{		
    	return preg_replace( '/\<title\>.*<\\/title\>/', '<title>' . 'My Custom Meta Title Here' . '</title>', $strContent );		
    	}
    }
    Not sure if this helps, but it does let you override the page title to whatever you want.
    Brian

  7. #7
    User
    Join Date
    04-05-10.
    Location
    Ukraine, Kiev
    Posts
    47

    Default Re: How to override page title?

    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

  8. #8
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: How to override page title?

    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

  9. #9
    User
    Join Date
    07-26-09.
    Posts
    175

    Default Re: How to override page title?

    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]

  10. #10
    User
    Join Date
    04-05-10.
    Location
    Ukraine, Kiev
    Posts
    47

    Default Re: How to override page title?

    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

  11. #11
    User
    Join Date
    06-19-09.
    Location
    Elbl?g, Poland
    Posts
    152

    Default Re: How to override page title?

    Quote Originally Posted by Terion
    From a template, sure? I've tried — it didn't...
    It's works, trust me. I've use this code in my projects. For example in Catalog module.
    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

  12. #12
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: How to override page title?

    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.

  13. #13
    User
    Join Date
    04-05-10.
    Location
    Ukraine, Kiev
    Posts
    47

    Default Re: How to override page title?

    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

  14. #14
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: How to override page title?

    Yeah -- thanks all.

    That's probably why it wasn't working for me either.
    Brian

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •