Welcome Guest, Not a member yet? Register   Sign In
About Sub Template
#1

[eluser]Unknown[/eluser]
Hello all,

I have a question about two forms to do something that for me are the same:

I have the next tree files,

Controller.php
Code:
function lista(){

$datos=array(
  'titulo' => 'Usuarios',
  'pagina' => $this->parser->parse('usuarios_lista',array(),TRUE),
  'test'  => 'Este es un test',
);

$this->parser->parse('template',$datos);
}

template.php
Code:
<h1>{titulo}</h1>
{pagina}

usuarios_lista.php
Code:
{test}

I can see the output in the browser:

Code:
<h1>Usuarios</h1>

Este es un test

But the problem is when I want use PHP inside the html code:

Controller.php
Code:
function lista(){

$datos=array(
  'titulo' => 'Usuarios',
  'pagina' => $this->load->view('usuarios_lista',array(),TRUE),
  'test'  => 'Este es un test',
);

$this->load->view('template',$datos);
}

template.php
Code:
<h1>&lt;? echo $titulo;?&gt;</h1>
&lt;? echo $pagina; ?&gt;

usuarios_lista.php
Code:
&lt;?echo $test;?&gt;

The code before said to me an error about test variable, that is unknown.

Someone has an idea for solve this problem?

Thanks in advanced Smile
#2

[eluser]Aken[/eluser]
When you load the usarios_lista view, you need to pass the "test" item through in the second parameter, where you currently have an empty array().

When you are using the template parser, the {test} item is not replaced until the template is loaded, so you don't need it when loading usarios_lista. However, when you want to use the raw PHP, usarios_lista needs that data since it is processed before the template.




Theme © iAndrew 2016 - Forum software by © MyBB