Template Parser Class Improvement |
[eluser]r.tahara[/eluser]
okay. thank you.. it works now.. i'll try the parse for a while then.. thanks
[eluser]r.tahara[/eluser]
oh ya.. before i try it.. are you missing the closing php tag at the bottom?
[eluser]rafsoaken[/eluser]
Hi, thanks for the improvements! I used it a bit and came across some bugs that I could remove and I also did a bit of cleanup - additionally you can now parse strings: Code: $this->parser->parse_str('value:{myvar}', array('myvar'=>23)); and access array variables like so: Code: $this->parser->parse_str('arrayvalue:{myarr akey}', array('myarr'=>array('akey'=>23))); [edit]: I added the possibility to check for boolean values: Code: $this->parser->parse_str('{if {booltrue}}yesss!{/if}', array('booltrue'=>true)); here is the MY_Parser class file: http://www.fragment.at/site/files/MY_Parser.phps and thats how the tests look like: http://www.fragment.at/site/files/testParser.phps hope that helps
[eluser]isaiahdw[/eluser]
[quote author="r.tahara" date="1203423789"]oh ya.. before i try it.. are you missing the closing php tag at the bottom?[/quote] Nope, I never include a closing php tag if the file is entirely php code. It's not required by php and prevents accidental trailing whitespace from creating problems with the output.
[eluser]isaiahdw[/eluser]
[quote author="rafsoaken" date="1205522806"]Hi, thanks for the improvements! here is the MY_Parser class file: http://www.fragment.at/site/files/MY_Parser.phps and thats how the tests look like: http://www.fragment.at/site/files/testParser.phps hope that helps [/quote] Thanks for posting an update to this class, I will take a look over it later on today.
[eluser]rafsoaken[/eluser]
Updated it again, now repeated and nested arrays (that didn't work before it seems) work: Code: //prepare template data here are the updated files: http://www.fragment.at/site/files/MY_Parser.phps and thats how the tests look like: http://www.fragment.at/site/files/testParser.phps happy parsing!
[eluser]deck1[/eluser]
I'm using the last example posted, but i don't know if i'm doing right. I want "post" to be another nested array: Code: $data = array( And the template: Code: {messages_div} But it didn't work. If i change "message" to: Code: 'message'=>array('title'=>'error') It works, but obviously for only one message. It's possible to do what i'm trying? Thanks in advance.
[eluser]rafsoaken[/eluser]
hi, you can try with only Code: $data = array( That should work..
[eluser]wiredesignz[/eluser]
Not to burst anyones bubble, but the parser should not be an object, it is a helper if anything. After all the CI View is not even an object. (and it probably should be) DEREK!! :lol:
[eluser]deck1[/eluser]
@rafsoaken Thanks for your fast reply. It didn't work. And the array you have delete is needed, because we have more "types" (like success, info...). The error message we get is: Code: Message: preg_match_all() [function.preg-match-all]: Compilation failed: nothing to repeat at offset 2 @wiredesignz I have searched in the forum looking for templating/parser best practices, but i didn't find almost anything. Can you post some examples/links? |
Welcome Guest, Not a member yet? Register Sign In |