Template Parser Class Problem |
[eluser]Deep Arora[/eluser]
Is there a way to use conditionals (if else) in the template parser? For example, I want to check if no records are returned in the resultset, then don't process the loop: Code: {resultset} is there a way to use "if" condition here? Code: {if resultset} ?
[eluser]rogierb[/eluser]
No, you can't. Well... not quite true, you can if you load the parsed template in a variable and eval() it. Then you can use PHP inside you template. Code: if ("{some_element}" !="") echo "blahblah";
[eluser]Phil Sturgeon[/eluser]
The Template Parser class is very limited. For better support, why not try working with Dwoo in your views?
[eluser]Deep Arora[/eluser]
Thanks..I checked that library: As an example it just shows: Code: $this->load->library('parser'); Code: {if dwoo_test} {message} {/dwoo_test} The problem I am facing is that a resultset is returned to the view. Now in view, I use Code: {resultset} If nothing is returned from the db, then this just displays the tags. Even if I populate the resultset as "No records found", it just replaces the first {resultset} tag. Rest of the things is shown as tags. In expression engine, I remember, we have something similar and we can use all conditionals too: Code: {weblog: name} etc Can same thing be achieved here?
[eluser]Deep Arora[/eluser]
[quote author="Phil Sturgeon" date="1264527544"]The Template Parser class is very limited. For better support, why not try working with Dwoo in your views?[/quote] Does this work with http://igniteyourcode.com/ocular ? I am using this template library..
[eluser]Phil Sturgeon[/eluser]
Yes, that syntax is wrong but as pseudo-code it is correct. Ocular Template looks like it uses $this->load->view(), not parser. You be able to return the template string, then parse it but I do not know enough about Ocular library for that. It's fully compatible with my Template library though. ;-)
[eluser]moodh[/eluser]
You can trick the parser with the following code: Controller: Code: if(logge_in()) { {if_logged_in}Welcome!{/if_logged_in} An empty array hides it, and an array containing one row (array(), which could be like.. 'hi' as well) will show it. |
Welcome Guest, Not a member yet? Register Sign In |