Welcome Guest, Not a member yet? Register   Sign In
Generic list generator helper with templates (ul, ol, select box, etc.)
#11

[eluser]johnwbaxter[/eluser]
Hey Jelmer!

I'm using your helper to generate a checkbox tree (parent child expandable and contractable) and need to set some of the items as being checked from values stored in the session.

Have you make your intended improvements to the helper which may help me with this?
#12

[eluser]Jelmer[/eluser]
Hey audiopleb,

It's been a while since I've looked at this helper. I never really finished the select part of the function and solved it in a crude way for a select box that needed the current option selected (with preg_replace).

The problem I ran into was how to implement this, mainly because I might want to be able to different kinds of selecting. The best option I thought of, that I haven't implemented until now, was to have an array passed with values you might want selected. That array replaces instances of {SELECTED} with its values in your template where its key is found. It should also have a key "default" that has the default value for replacing when the replacement value is empty.

I think the replacement should probably happen after the alternation.

The array might look like this:
Code:
array(
    'default' => 'selected="selected"',
    'value="something"',
    'value="nothing"' => 'disabled="disabled"',
    'value="second_something"'
);

With which you would replace the {SELECTED} with true selections for the values "something" and "second_something" and disable the value "nothing".

I don't have time to write it now, maybe this weekend I might try it.
#13

[eluser]johnwbaxter[/eluser]
Ah cool, i was just being lazy and seeing if you'd done it before i had to!!!

I'll have a look at your idea and have a little go at incorporating it.
#14

[eluser]JimmyJ[/eluser]
How would think work if I was creating a menu. For example my code:
Code:
/************************
        * DO MAIN MENU
        ************************/
        $menu_name = 'main';
        $parent = 0;
        $order = 'position ASC';
        
        $this->menu_model->getStructure($menu_name, $parent, $order);
        $this->load->helper('generate_list');
        
        $resource = $this->menu_model->getStructure($menu_name, $parent, $order);
        
        $options = array(
            'template_head'=>'<ul>',
            'template_foot'=>'</ul>',
            'indent'=>'   |'
        );
        
        $template = '<li><a href="{URL_KEY}">{MENU_NAME}</a> {SUBS}</li>';
        
        $menu = generate_list($resource, $options, $template);
        
        $data['menu'] = $menu;
        /***********************/


Which produces


Code:
<ul>

<li><a href="home">Home</a></li>
<li><a href="about">About</a>
    <ul>
       <li><a href="staff">Staff</a></li>
   </ul>
</li>

</ul>

Ideally the staff page would be /about/staff - as it's a sub-menu of about. Same if it was 3 levels deeps. Can I do this using your helper?
#15

[eluser]Jelmer[/eluser]
Not easily, as there are some callback options you might make it possible yourself but I don't think it can out of the box. Having said that, it's been ages since I wrote this and I haven't used it in over a year so my memory might be lacking.
#16

[eluser]JimmyJ[/eluser]
That's what I thought, I've been a little late to the game Smile

I'll have a look and see if I can come up with anything. Thanks though, it's been really handy so far.




Theme © iAndrew 2016 - Forum software by © MyBB