Jump to content

Get current templatefile (or page) in sidebar hooks


Recommended Posts

Hi All,

Try trying to get the templatefile variable inside the ClientAreaSecondarySidebar hook so I can hide certain menu items depending what page is loaded. For example, on the domain registration page I don't want to display the categories sidebar. The below unfortunately doesn't work as $smarty->getVariable('templatefile')->value doesn't work. There is a variable $templatefile which contains the value 'domainregister' if I use {debug} on the tpl page. However, I don't seem to be able to retrieve it in the global smarty variables. It's of course not exposed in the secondarysidebar variables either. Any idea how to do this? Thanks. Will.

add_hook('ClientAreaSecondarySidebar', 1, function($secondarySidebar)
{
    
    GLOBAL $smarty;
    $activeFile = $smarty->getVariable('templatefile')->value;
    $activeTemplate = $_SESSION['Template'];
    
    if ($activeTemplate == 'portal') && $activeFile == 'domainregister') {
        if (!is_null($secondarySidebar->getChildren())) {
            foreach ($secondarySidebar->getChildren() as $sidebarItem){
                if ($sidebarItem->getName() == "Categories") {
                    $secondarySidebar->removeChild($sidebarItem->getName());
                }           
            }
        }
    }
});

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