Welcome Guest, Not a member yet? Register   Sign In
Extended Parser functionality?
#3

[eluser]moodh[/eluser]
Even if it's "ugly" it might be warranted to keep the views clean, most of CI's templateclass can be sorted with a hack and a foreach before sending to the view:
Code:
<?php
foreach($q->result_array() as $k => $v) {
  $v['key'] = $k; // set the key as you asked in your first question
  $o[] = $v;
  
}
// above should be in a model, and $data['variables'] should be set by a model call, but whatever for now
$data['is_logged_in'] = array(); // trick to emulate if-block: if(false)
$data['is_not_logged_in'] = array(array()); // trick to emulate if-block: if(true)
$data['variables'] = $o;
$this->parser->parse('view.php', $data);
?>

which means you can use the following in the parsed view:
Code:
{variables}
  {key} is the iteration
  {whatever}
  {whatever2}
{/variables}

{is_logged_in}you're logged in, yey!{/is_logged_in}
{is_not_logged_in}please login!{/is_not_logged_in}

With variables, loops and simple if-statements most things can be solved in the model (or controller) but it's of course more resource heavy, but sometimes nice views is actually worth it =)

There's a few hacks to the parser class to allow multiple blocks of the same name (for example {is_logged_in} twice), and also some other various improvements, search abit and you'll find them!


Messages In This Thread
Extended Parser functionality? - by El Forum - 09-29-2009, 03:00 PM
Extended Parser functionality? - by El Forum - 09-29-2009, 04:01 PM
Extended Parser functionality? - by El Forum - 09-29-2009, 05:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB