Jump to content

Set title of page using an action hook


Recommended Posts

There are a few parts to this, so I'll try explain the best I can.

 

We have a web site that has multiple custom pages - our main content is shown on these pages. Instead of creating lots of PHP files, I have made page.php and load custom content depending on the URL. This is handled through a simple .htaccess rewrite rule. page.php has the following content:

 

<?php

define("CLIENTAREA",true);
require("init.php");

$ca = new WHMCS_ClientArea();
$ca->initPage();

...

$slugs = array('domains', 'web-design', 'web-hosting');
$slug = $_GET['slug'];
if (in_array($slug, $slugs)) {
   $slug = '404';
}

$ca->setTemplate('pages/' . $_GET['slug']);
$ca->output();

?>

 

In header.tpl I want to show a menu, but to do so there needs to be some code that figures out the links, active pages, page titles, breadcrumb, etc. But if I put this code in page.php then it won't show up on normal client pages. I decided to put it in a hook, that would setup the data as template variables to be used in header.tpl. I wrote a function which returns the correct data and made the hook like so:

 

add_hook('ClientAreaPage', 1, 'hook_headersetup');

 

This works fine for both pages I created and normal client pages in WHMCS. However, on my custom pages I also want to set the title, breadcrumb, etc. In page.php I can use code like this:

$ca->setPageTitle()

and [php$ca->addToBreadCrumb()[/php], however the variables that are setup in the ClientAreaPage hook aren't available here.

 

What should I do in this case?

 

Many thanks.

Link to comment
Share on other sites

you need to use the custom page code instead of Action Hook, you can pass the $slug value to header.tpl from same page..

 

$ca->assign("slug", $slug);
$ca->setTemplate('pages/' . $slug); 
$ca->output(); 

 

in header.tpl you can use it like follow:

{if $slug=='domains'}
// display domains specific content
{elseif $slug=='web-design'}
// display web-design specific content
{else}
{/if}

Link to comment
Share on other sites

to set title using Action Hook it will be like this:

 

<?php

function hook_setpagetitle($vars){

$pagetitle = "Set Page Title Here";

// also you can set title per page URL
if ($vars['filename']=='index'){
   $pagetitle = "Home Page";
}
elseif ($vars['filename']=='domains'){
   $pagetitle = "Domains Custom Title";
}

return array("pagetitle" => $pagetitle);
}
add_hook("ClientAreaPage", 1, "hook_setpagetitle");

?>

 

- - - Updated - - -

 

as far as i know you will be unable to edit or control breadcrumbs from Action Hook, but you can use tricks inside template file to modify it a little

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated