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

[eluser]darkhouse[/eluser]
Ok, I think I can attribute my issue to the fact that it was 3am when I was trying to get it to work and I obviously missed something. I ended up doing what I needed a different way and so far things are working fine.

However, I needed something similar yesterday and decided to try it again, and it worked first try. I needed this:

Code:
{if {page1:slug}=='programs'}
<ul class="menu"> etc etc </ul>
{/if}

And it worked perfectly, so I'm pretty sure I just screwed something up when I was trying to do logged_in:admin - I may revisit that later to get it working the way I originally wanted, but for now it's fine.
#62

[eluser]GDmac - expocom[/eluser]
So darkhouse, now you may teach me something new.
What is this colon reference in page1Confusedlug ?
i haven't seen that before, is it an object, an array element?
#63

[eluser]darkhouse[/eluser]
It's an object - I could've easily have done {page1_slug} but I like the colon syntax. I'm building a CMS solution and in this case I needed some menus to display for specific paths, so rather than create separate templates, I made just one template that had some conditions. I have a library that does all my CMS stuff, which gets the pages based on the uri, so if the uri is /foo/bar it gets the foo page for page1, and then the bar page for page2, and it displays the last page in the _pages array. Here's my code for creating the page1Confusedlug stuff

Code:
for($i = 0, $l = 10; $i < $l; $i++){
    $key = 'page'.($i+1);
    $data[$key.':slug'] = '';
    $data[$key.':title'] = '';
    if(isset($this->_pages[$i])){
        $data[$key.':slug'] = $this->_pages[$i]->slug;
        $data[$key.':title'] = $this->_pages[$i]->title;
    }
}

I figure no site will ever have more than 10 page tiers, so I limited it to 10. I loop through and set the values to nothing, and then check to see if there is a page at that tier, and I replace the values.

So then in my template, I've done this:

Code:
{if {page1:slug}=='centre'}
<ul class="menu">
    <li><a href="centre/about-us">About us</a></li>
    <li><a href="centre/advisory-councils">Advisory Councils</a>
        {if {page2:slug}=='advisory-councils'}
        <ul class="submenu">
            <li><a href="centre/advisory-councils/family-terms-of-reference">Family &amp; Terms of Reference</a></li>
            <li><a href="centre/advisory-councils/youth-terms-of-reference">Youth &amp; Terms of Reference</a></li>
        </ul>
        {/if}
    </li>
    <li><a href="centre/news">News</a>
        {if {page2:slug}=='news'}
        <ul class="submenu">
            <li><a href="centre/news/latest-news">Latest News</a></li>
            <li><a href="centre/news/grandviews-newsletter">Grandviews Newsletter</a></li>
            <li><a href="centre/news/media-kit">Media Kit</a></li>
        </ul>
        {/if}
    </li>
    <li><a href="contact">Contact Us</a></li>
</ul>
{/if}

Eventually I'll be turning this into a module so the menus will be completely dynamic instead of semi-static, but for now this is working great.
#64

[eluser]Juan Ignacio Borda[/eluser]
does someone knows how to parse this:

Code:
$cpData['colours'] = array(
            array('name' => 'red'),
            array('name' => 'blue'),
            array('name' => 'green'),
            array('name' => 'yellow',
                'fruits' => array(array('fname' => 'banana'),array('fname' => 'Lime'))
            ),
        );

I've tried with:
Code:
<ul>
    {colours}
    <li>
        {name}
        <ul>
            {fruits}
            <li>
                {fname}
            </li>
            {/fruits}
        </ul>
    </li>
    {/colours}
</ul>

but i get:

A PHP Error was encountered

Severity: Warning

Message: preg_match_all() [function.preg-match-all]: Compilation failed: nothing to repeat at offset 2

Filename: libraries/Parser.php

Line Number: 475
#65

[eluser]darkhouse[/eluser]
I'm not sure exactly, but maybe your issue is that you don't have a 'fruits' array in the first 3 elements.
#66

[eluser]Juan Ignacio Borda[/eluser]
[quote author="darkhouse" date="1302122522"]I'm not sure exactly, but maybe your issue is that you don't have a 'fruits' array in the first 3 elements.[/quote]

nope! is not that it has somethig to do with _parse_pair being called with wrong arguments at line 450
#67

[eluser]Juan Ignacio Borda[/eluser]
Solved the problem (don't know if it has some other side effect )

at line 449
changed from:
Code:
$temp = $this->_parse_pair($key, array($key=>$val), $temp);
to
Code:
$temp = $this->_parse_pair($key, $val, $temp);

please update library if it's right!
#68

[eluser]GDmac - expocom[/eluser]
Juan, that could well be. the parse_pair method was not written by me and I haven't tested this with nested arrays nor nested pairs. Could you do some regression tests and maybe add one or two tests to the parser test controller? Maybe a good moment to put this up at github or bitbucket.

Darkhouse, there are several other parsing libraries that use the colon in tags for calling functions or accessing multi-dimensional arrays. I would try to avoid using that colon syntax in variable names or array keys.
#69

[eluser]darkhouse[/eluser]
Will this library be doing anything with colons in the future? I would love it if it did, so I didn't have to write my own.

Also, on a side note, I would love to be able to do something like this:

Code:
{posts}
    {publish_time:M j, Y}
{posts}

I need some way of formatting dates and times. Right now I'm building setting it manually on the object, but then it's hard coded into the object, I'd rather it be formatted by the template so that each use could be different. I mean, I could just setup a property for each possible format I might want to use, but that's silly.
#70

[eluser]bahjaat[/eluser]
[quote author="Juan Ignacio Borda" date="1302126089"]Solved the problem (don't know if it has some other side effect )

at line 449
changed from:
Code:
$temp = $this->_parse_pair($key, array($key=>$val), $temp);
to
Code:
$temp = $this->_parse_pair($key, $val, $temp);

please update library if it's right![/quote]

Dude, this is awesome...
Was running into the same problem. Had cost me 1 day and you helped my out right now!
Thanks a lot.




Theme © iAndrew 2016 - Forum software by © MyBB