LeonardChallis Posted May 30, 2015 Share Posted May 30, 2015 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. 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted May 30, 2015 Share Posted May 30, 2015 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} 0 Quote Link to comment Share on other sites More sharing options...
LeonardChallis Posted May 30, 2015 Author Share Posted May 30, 2015 But then if it's not in a hook, the non-custom client pages won't have the menu and other variables available to them the same as custom pages. That's why I put it into a hook - so that they'd be available everywhere. 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted May 30, 2015 Share Posted May 30, 2015 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 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.