[SOLVED] Adding to/setting page title from within a module

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
User avatar
kidcardboard
Forum Members
Forum Members
Posts: 54
Joined: Mon Sep 28, 2009 5:25 pm

[SOLVED] Adding to/setting page title from within a module

Post by kidcardboard »

Is it possible? I've tried

Code: Select all

$contentobj = $gCms->variables['content_obj'];
$contentobj->mName = "Lorem ipsum | {$contentobj->mName}";
but by the time this code runs the page title has already been set. I could've sworn that I've come across this before and found a solution for it, but I think that was well over a year ago and I can't even remember what project that was for nevermind being able to find it in the forums.
Last edited by kidcardboard on Wed Sep 21, 2011 9:45 pm, edited 1 time in total.
User avatar
kidcardboard
Forum Members
Forum Members
Posts: 54
Joined: Mon Sep 28, 2009 5:25 pm

Re: Adding to/setting page title from within a module

Post by kidcardboard »

Right after I posted this I had a hunch where I did it and was right. For anyone else who is curious how to do this it is as follows.

In your page template remove

Code: Select all

{process_pagedata}
and replace it with

Code: Select all

{content assign="capturedcontent"}
Then change your title tag to

Code: Select all

<title>{if isset($pagetitle)}{$pagetitle}{else}{title}{/if}</title>
or structure it however you want. Then from within your module you can set {$pagetitle} to whatever you want.
Then replace

Code: Select all

{content}
with

Code: Select all

{$capturedcontent}
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: [SOLVED] Adding to/setting page title from within a modu

Post by calguy1000 »

Your instructions are just... well wrong... I blogged and wrote an article about this YEARS ago.

Step 1:
ensure $config['process_whole_template'] = false; in the config.php

Step 2:
In your module template code (usually a detail template) do something like:
{assign var='title' value=$entry->title}

Step 3:
In your page template:
<title>{if isset($title)}{$title}{else}{title}{/if}</title>
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
kidcardboard
Forum Members
Forum Members
Posts: 54
Joined: Mon Sep 28, 2009 5:25 pm

Re: [SOLVED] Adding to/setting page title from within a modu

Post by kidcardboard »

That's much easier. Thanks.
Post Reply

Return to “Developers Discussion”