Hi!
I am learning CI4 and I got to the point that I was waiting for: View Parser. I am making some tests but am having a hard time trying to include partials with it. This is my pathetic attempt...
The View (produtos_testeForeach.php):
Code:
{header}
<div>
<h1>{titulo}</h1>
<hr>
<table>
<tr>
<th><h2>PRODUTO</h2></th>
<th><h2>PREÇO</h2></th>
</tr>
{conteudo}
<tr>
<td>{produto}</td>
<td>{preco}</td>
</tr>
{/conteudo}
</table>
</div>
</body>
</html>
The Controller:
PHP Code:
public function testeForeach() {
$data['titulo'] = 'Meu titulo';
// Produtos_header.php is an existing view that I tried to render into a variable
$header = view('produtos_header',$data);
$parser = \Config\Services::parser();
$data = [
// Then I tried to load the contents of this var into array 'header' entry
'header' => $header,
'titulo' => 'Isso é um título de teste',
'conteudo' => [
['produto' => 'produto1', 'preco' => '10,00'],
['produto' => 'produto2', 'preco' => '20,00'],
['produto' => 'produto3', 'preco' => '30,00'],
['produto' => 'produto4', 'preco' => '40,00'],
['produto' => 'produto5', 'preco' => '50,00'],
]
];
return $parser->setData($data)->render('produtos_testeForeach');
OK... it ALMOST worked. LoL!
The problem is that when it rendered the 'produtos_testeForeach' view instead to render the header partial as HTML it is showing it on screen as plain text:
Code:
<!-- DEBUG-VIEW START 1 APPPATH/Config/../Views/produtos_header.php --> <html> <head> <title>Meu titulo</title> </head> <body> <div id="header"> <h1>Sistema de Controle de Produtos</h1> <hr> </div> <!-- DEBUG-VIEW ENDED 1 APPPATH/Config/../Views/produtos_header.php -->
How can I fix it, aka, how can I load partial views into a view?
Thanks!
Recovering the wasted time...