Welcome Guest, Not a member yet? Register   Sign In
Template Parser Class Improvement
#31

[eluser]wiredesignz[/eluser]
Template parser helper
http://ellislab.com/forums/viewthread/72929/
#32

[eluser]rafsoaken[/eluser]
ok, its true that for deeper nested arrays the parser is not suited, but this works:
Code:
$data = array(
                'messages_div'=>array(
                            array('type'=>'error', 'msg' => array('title'=>'error1', 'text'=>'an error msg')),
                            array('type'=>'notice', 'msg'=> array('title'=>'notice1', 'text'=>'an notice msg'))
                )
        );

with that template:
Code:
{messages_div}
<p>{type}</p>
<ul>
{msg}
    <li>{title}<br />{text}</li>
{/msg}
</ul>
{/messages_div}
cheers

(btw, there is a test file also - you can see all the use cases in there.. just browse and see if that suits your needs)
#33

[eluser]deck1[/eluser]
Hi rafsoaken. Thanks for the example. The limitation in this example is that only the first row array is parsed, the following arrays must be k/v arrays.

A solution may be to check if the next array to parse is a k/v or row array with:

Code:
if(is_numeric($key) && is_array($val)) {
//is a row array, dont parse as k/v
}

But i don't know where to put that check.
#34

[eluser]rafsoaken[/eluser]
hi could you give an example of the sample input data (and which array you are talking about exactly) ? thx
#35

[eluser]deck1[/eluser]
The input data:

Code:
$data = array(
    'messages_div'=>array(
                array('type'=>'error',
                            'message'=> array(
                            array('title'=>'error1'),
                            array('title'=>'error2')
                            )
                        )
                                  
                  )
         );

and the template:

Code:
{messages_div}    
    <p>{type}</p>

        <ul>
            {message}

                <li>{title}</li>

            {/message}
        </ul>
{/messages_div}

The problem comes with "message" array, the parser expects a key/value array like this:

Code:
'message'=> array('title'=>'error1', 'another_key'=>'another_value')

But not a row array:

Code:
'message'=> array(
    array('title'=>'error1'),
    array('title'=>'error2')
)
#36

[eluser]rafsoaken[/eluser]
Just looked into it again - the thing is, that the parser doesn't let you jump array keys to more nested levels. thus you can't use
Code:
{message} {title} {/message}
if there is no "title" key in the message array but only in the containing arrays below.

To change this it would take probably bigger changes to the structure of the parser, than I can make now (feel free to post patches here! I can also help you set up the tests if you want.)
So in conclusion: if you can fit your data easily with the examples provided (ie.: provide the keys to your arrays you iterate on), then its good to use. If you want something more specific or nested, you'd be better off with something else.
#37

[eluser]deck1[/eluser]
I was trying to solve that and... It works ok with native CI parser. :lol:
#38

[eluser]rafsoaken[/eluser]
interesting.., might be that the extras of this one have a backdraw on another side then..
#39

[eluser]Mirage[/eluser]
You could use Smarty. OR you could wait for EE2.0 which might give CI some nifty template parser enhancements.

I'm just saying...
#40

[eluser]m4rw3r[/eluser]
Or make your own Tongue




Theme © iAndrew 2016 - Forum software by © MyBB