Can we use {variable} in CodeIgniter Views?

4

I know that we can use Views.html file in CodeIgniter, now I would like to know if we can use {variavel} tags directly like in Smarty.

Example:

<body>
  <h1>{msg}</h1>
</body>

Are there any native replacement functions? Or do you have to use a coupled framework?

I would like to completely separate PHP from HTML, I already do this with a class of its own, but I wonder if CodeIgniter already does this.

By way of example in substitution:

$data = array();
$CI = & get_instance();
$page = $CI->load->view('login.html', $data, true);
echo   str_replace("{teste}", "Hello World", $page);
    
asked by anonymous 22.12.2015 / 15:21

1 answer

2

The codeigniter has a parser library for this you need, take a look link

And for purposes of leaving here as it would be something like this:

// carrega a library
$this->load->library('parser');

// le/gera os dados
$data = array(
            'blog_title' => 'My Blog Title',
            'blog_heading' => 'My Blog Heading'
        );

// carrega a view blog_template e passa os dados
$this->parser->parse('blog_template', $data);

and the view would look something like:

<html>
    <head>
        <title>{blog_title}</title>
    </head>
    <body>

        <h3>{blog_heading}</h3>

    </body>
</html>
    
28.12.2015 / 17:46