Show
Ignore:
Timestamp:
11/13/08 11:53:39 (16 months ago)
Author:
JensDiemer
Message:

Add splitting function for the main_menu. Contributed by Manuel Herzog, see: http://www.pylucid.org/phpBB2/viewtopic.php?t=254 (de)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid_project/PyLucid/plugins_internal/main_menu/main_menu.py

    r1634 r1792  
    1818    Last commit info: 
    1919    ~~~~~~~~~~~~~~~~~ 
    20     $LastChangedDate: $ 
     20    $LastChangedDate$ 
    2121    $Rev$ 
    22     $Author: $ 
     22    $Author$ 
    2323 
    2424    :copyleft: 2007 by the PyLucid team, see AUTHORS for more details. 
     
    3737class main_menu(PyLucidBasePlugin): 
    3838 
    39     def lucidTag(self): 
     39    def lucidTag(self, min=1, max=0): 
    4040        """ 
    4141        write the current opened tree menu 
     
    4343        current_page = self.context["PAGE"] 
    4444        self.current_page_id  = current_page.id 
     45        self.min = min 
     46        self.max = max 
    4547 
    4648        # Get the menu tree dict from the database: 
     
    5254        context = { 
    5355            "menu": menu_html, 
     56            "min": min, 
     57            "max": max 
    5458        } 
    55         self._render_template("main_menu", context) 
     59        self._render_template("main_menu_ul", context) 
    5660 
    5761 
     
    6367 
    6468        for entry in menu_data: 
    65  
    6669            # Generate the absolute url to the page: 
    6770            href = [] 
     
    7376            entry["href"] = "/" + href + "/" 
    7477 
    75             if entry.has_key("subitems"): 
    76                 # go recusive deeper into the menu entries 
    77                 entry["submenu"] = self.get_html(entry["subitems"], parent=href) 
    78             else: 
    79                 entry["submenu"] = "" 
     78            if (int(entry["level"]) <= self.max or self.max<self.min) and \ 
     79                                            int(entry["level"]) >= self.min: 
    8080 
    81             if entry["id"] == self.current_page_id: 
    82                 # Mark the last menu item, the current displayed page 
    83                 entry["is_current"] = True 
     81                if entry.has_key("subitems"): 
     82                    # go recusive deeper into the menu entries 
     83                    entry["submenu"] = self.get_html( 
     84                        entry["subitems"], parent=href 
     85                    ) 
     86                else: 
     87                    entry["submenu"] = "" 
    8488 
    85             # Render one menu entry 
    86             html = self._get_rendered_template("main_menu_li", entry) 
    87             result.append(html) 
     89                # Render one menu entry 
     90                html = self._get_rendered_template("main_menu_li", entry) 
     91                result.append(html) 
     92            elif int(entry["level"]) < self.min: 
     93                if entry.has_key("subitems"): 
     94                    html = self.get_html(entry["subitems"],parent=href) 
     95                    result.append(html) 
    8896 
    89         context = { 
    90             "menu": mark_safe("\n".join(result)), 
    91         } 
    92  
    93         # render all menu entries into a <ul> tag 
    94         menu_html = self._get_rendered_template("main_menu_ul", context) 
     97        if result == []: 
     98            menu_html = "" 
     99        else:            
     100            menu_html = "\n".join(result) 
    95101 
    96102        return mark_safe(menu_html) 
    97