Welcome Guest, Not a member yet? Register   Sign In
Dynamic code in view variables
#1

[eluser]Unknown[/eluser]
I'm trying to figure out how best to tackle parsing variable code. Essentially I want to do something like this:

Controller:

Code:
$data = array();
$data['heading'] = 'Thanks for registering';
$data['content'] = $template_content //I fetched this from the database

$this->load->view('message', $data);

View message.php:

Code:
<html>
  <head>
    <title><?=$heading?></title>
  </head>
  <body>
    <?=$content?>
  </body>
</html>

BUT to have $content parsed as if it were another view file; ie processing php loops, conditionals and perhaps other CI code. I guess it's similar to $this->parser->parse_string($content) the CI templating class, but I need to handle things like nested conditionals as well as the simple loops it offers.

My only guess at the moment is to dynamically create view files and load them within the main message.php view... but it's not very attractive :| Maybe extending the core loader class? But ideally something simpler!




Theme © iAndrew 2016 - Forum software by © MyBB