Parser and if statement |
Hi,
I use parser for sending data from controller into view, but don't know how to now make if statement in view. If I have for example view like this: Code: <html> How to write if statement for title? I wanna to check if title for example "Michael" to write in view "Michael is the best", and for all other records to write |Welcome". Any help?
Hello!
Unfortunately, this is not possible. As you can see on Template Parsing library: Quote:The Template Parser Class is not a full-blown template parsing solution. We’ve kept it very lean on purpose in order to maintain maximum performance. Try to iterate your entries in your controller and set the title directly from there: PHP Code: foreach($blog_entries as &$entry) Hope this helps.
This is my original code in contoller
PHP Code: $query = $this->users_mod->allProducts(); In view I go like this: Code: <tbody> How to change my controller to get in view for active what I want to? I want to if {active} == 1 to write active, and if {active} == 0 to write disabled. Can you help me?
Change your controller code as this:
PHP Code: $query = $this->users_mod->allProducts();
That doesn't work. Should I use some template engine or something like that?
I don't see why it shouldn't work. Are you sure the field is called active?
In my opinion, you shouldn't use the parsing solution. Instead, send the data to your view and iterate it from there: PHP Code: <tbody>
I have to use parse, it's was requested by client.
Do you have some advice how to solve this problem, to use some template engine as twig or something like that?
LOL, bloody clients.....
It is quite easy to implement a full blown parser like twig, you could do that. It is a bit bloated though. Are you in a position to argue/discuss the parsing thing with the client? A full blown parser offers if, foreach and switch statements that are very user friendly for designers. gxpet is right, that approach should work. When you say it does not work, why does it not work?
It works without parser, but as I said I have to use parser .
Beside twig, which template engine also I should consider?
If you want to try something a little more powerful than the CI parser you could give lex a shot. I has a MIT License and is available here https://github.com/pyrocms/lex
I have used it on many occasions with pretty good success. |
Welcome Guest, Not a member yet? Register Sign In |