1
nachenko
Include block by hand in theme
  • 2006/11/22 12:00

  • nachenko

  • Quite a regular

  • Posts: 356

  • Since: 2005/1/18


Hi!

I'm trying to include the system menu in a theme. Instead of locating it on one of the predefined places i'm trying to call it from the theme.html file, doing this:

Quote:

<{php}>
// Show main menu in top of the page
require_once (XOOPS_URL."/modules/system/blocks/system_blocks.php");
$mainmenu = b_system_main_show();

etc...


Is you see, I include the file that defines the block. Then call teh function that generates the PHP data that I later use to build the menu.

Everything goes fine until i remove the mainmenu conventional block, then I receive a 'fatal error: call to undefined funcion "b_system_main_show"'

What's wrong? I require the file that contains that function, so I'm sure it has been properly loaded. The functions scoop is suposed to be global. What am I doing wrong?

2
hervet
Re: Include block by hand in theme
  • 2006/11/22 12:08

  • hervet

  • Friend of XOOPS

  • Posts: 2267

  • Since: 2003/11/4



3
nachenko
Re: Include block by hand in theme
  • 2006/11/22 12:15

  • nachenko

  • Quite a regular

  • Posts: 356

  • Since: 2005/1/18


Man, thanks a lot. This fix the problem, but I still have the curiosity. What's wrong in my script?

4
nachenko
Re: Include block by hand in theme
  • 2006/11/22 13:14

  • nachenko

  • Quite a regular

  • Posts: 356

  • Since: 2005/1/18


uh, fixed.

Should replace XOOPS_URL by XOOPS_ROOT_PATH.

That was all. Anyway, BOOX is a simple and great idea.

5
hervet
Re: Include block by hand in theme
  • 2006/11/22 13:16

  • hervet

  • Friend of XOOPS

  • Posts: 2267

  • Since: 2003/11/4


thanks

6
abrizan
Re: Include block by hand in theme
  • 2007/1/21 12:41

  • abrizan

  • Just popping in

  • Posts: 82

  • Since: 2005/11/14


I had the same problem so I came up with this php snippet. Just put it right in before your HTML tag:

<{php}>
//*********************   custom main menu    *********************//
// There must be an easier way to achieve this but this is what I  //
// came up with. Smarty programming seems to be acting wierd in a  //
// template so i have to do it the old fashioned way: straight PHP //
// Broke up the menu building into simple functions to keep HTML   //
// tags out of the menu code. ONLY EDIT THE $htmlcode="..."; LINES //
// It's dirty but it works.                                        //
// -xoopstuner                                                     //
//*****************************************************************//

//mini template for custom main menu
function xtnrMenu($Menu,$activeModuleName,$activeModuleLink,$activeModuleSublinks){
    
$htmlcode="
    | .XOOPS_URL." >Home |$Menu
    "
;
    return 
$htmlcode;
}


//mini template for menu link and sublinks placement
function xtnrMenuLink($linktitle,$link,$sublinks){
    
$htmlcode="
    $link >$linktitle |
    "
;
    return 
$htmlcode;
}


//mini template for menu link when there are no sublinks, active takes precidence
function xtnrMenuLinkEmpty($linktitle,$link){
    
$htmlcode="
    $link >$linktitle |
    "
;
    return 
$htmlcode;
}


//mini template for menu link and sublinks placement for currently selected module
function xtnrMenuLinkActive($linktitle,$link,$sublinks){
    
$htmlcode="
    $link >$linktitle |
    "
;
    return 
$htmlcode;
}


//mini template for sublinks 
function xtnrMenuSublink($linktitle,$link){
    
$htmlcode="
    ---$link >$linktitle

    "
;
    return 
$htmlcode;
}


//mini template for sublinks of currently active module
function xtnrMenuSublinkActive($linktitle,$link){
    
$htmlcode="
    ---$link >$linktitle-active

    "
;
    return 
$htmlcode;
}



    
    
//modified main menu block code
    
global $xoopsUser,$xoopsModule,$customMainMenu,$activeModuleName,$activeModuleLink,$activeModuleSublinks,$temp;
    
$block = array();
    
$block['lang_home'] = _MB_SYSTEM_HOME;
    
$block['lang_close'] = _CLOSE;
    
$module_handler =& xoops_gethandler('module');
    
$criteria = new CriteriaCompo(new Criteria('hasmain'1));
    
$criteria->add(new Criteria('isactive'1));
    
$criteria->add(new Criteria('weight'0'>'));
    
$modules =& $module_handler->getObjects($criteriatrue);
    
$moduleperm_handler =& xoops_gethandler('groupperm');
    
$groups is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
    
$read_allowed =& $moduleperm_handler->getItemIds('module_read'$groups);
    foreach (
array_keys($modules) as $i) {    
        if (
in_array($i$read_allowed)) {
            
$modulesname $modules[$i]->getVar('name');
            
$moduledirectory $modules[$i]->getVar('dirname');
            
$sublinks =& $modules[$i]->subLink();
            
$sublinkshtmlout '';


            if (empty(
$xoopsModule)) {
                
//system module; fill in defaults
                
$mid=-1;
                
$activeModuleName="Home";
                
$activeModuleLink=XOOPS_URL;
                
$activeModuleSublinks='';
            } else {
                
$mid=$xoopsModule->getVar('mid');
            }
            

            
//build sublinks for module
            
if ((count($sublinks) > 0)) {
                if (
$i == $mid) {
                    foreach(
$sublinks as $sublink){
                        
//current active  module
                        
$sublinkshtmlout =$sublinkshtmlout.xtnrMenuSublinkActive ($sublink['name'],XOOPS_URL.'/modules/'.$modules[$i]->getVar('dirname').'/'.$sublink['url'] );
                        
$activeModuleSublinks =$activeModuleSublinks.xtnrMenuSublinkActive ($sublink['name'],XOOPS_URL.'/modules/'.$modules[$i]->getVar('dirname').'/'.$sublink['url'] );
                    }    
                } else {
                    foreach(
$sublinks as $sublink){
                        
//not current active module
                        
$sublinkshtmlout =$sublinkshtmlout.xtnrMenuSublink     ($sublink['name'],XOOPS_URL.'/modules/'.$modules[$i]->getVar('dirname').'/'.$sublink['url'] );
                    }
                }
            } else {
                
$block['modules'][$i]['sublinks'] = array();
            }


            
            
// Build Main Menu Link From mini template
            
if ($i == $mid) {    
                
//current active module
                
$activeModuleName $modulesname;
                
$customMainMenu $customMainMenu.xtnrMenuLinkActive($modulesnameXOOPS_URL.'/modules/'.$moduledirectory$sublinkshtmlout);
                
$activeModuleLink $activeModuleLink.xtnrMenuLinkActive($modulesnameXOOPS_URL.'/modules/'.$moduledirectory$sublinkshtmlout); 
            } else {
                
//not current active module
                
if ($sublinkshtmlout==''){
                    
$customMainMenu =$customMainMenu.xtnrMenuLinkEmpty($modulesnameXOOPS_URL.'/modules/'.$moduledirectory);
                } else {
                    
$customMainMenu =$customMainMenu.xtnrMenuLink($modulesnameXOOPS_URL.'/modules/'.$moduledirectory$sublinkshtmlout);
                }
            }
                                    
        }
    }
    
$customMainMenu xtnrMenu($customMainMenu,$activeModuleName,$activeModuleLink,$activeModuleSublinks);
    
//no output if no modules
    
if (count(array_keys($modules))==0) {$customMainMenu ='';}

<{/
php}>




In the template where I want my custom main menu I put
<{php}>echo ($customMainMenu);<{/php}>


I have used this in a few of my templates, including one which makes a popup menu based on the GOSU menu script in the admin theme of XOOPS 2.2
You shouldn't have to modify anything but the 'mini templates' at the beginning of the script to fit your theme.

You can download a theme with it at http://www.xoopstuner.com xtnrBusiness is what this is pasted from and xtnrPortable has the popup menu script in it, twice.

Login

Who's Online

205 user(s) are online (79 user(s) are browsing Support Forums)


Members: 0


Guests: 205


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits