![]() |
How to load partials with View Parser? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10) +--- Thread: How to load partials with View Parser? (/showthread.php?tid=76219) |
How to load partials with View Parser? - YanKleber - 04-22-2020 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} The Controller: PHP Code: public function 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! RE: How to load partials with View Parser? - YanKleber - 04-23-2020 Okay, I figured it myself. I thought about this overnight and this morning I took a look in the source that was being generated (something I didn't think of last night when I started this thread). I realized that the parser was escaping the special characters turning < and > into < and > respectively -- and that's why it was showing code as plain text instead to interpret it as HTML. The solution was fairly simple. Just had to apply the htmlspecialchars_decode native function on parser var this way: PHP Code: return htmlspecialchars_decode($parser->setData($data)->render('produtos_testeForeach')); Maybe there is simpler ways of solving it (like setting some configuration in CI or so) but it fixed the issue for me! ![]() RE: How to load partials with View Parser? - InsiteFX - 04-23-2020 Using the Parser, your view templates are processed only by the Parser itself, and not like a conventional view PHP script. PHP code in such a script is ignored by the parser, and only substitutions are performed. RE: How to load partials with View Parser? - YanKleber - 04-23-2020 (04-23-2020, 07:58 AM)InsiteFX Wrote: Using the Parser, your view templates are processed only by the Parser itself, and not like a conventional view PHP script. PHP code in such a script is ignored by the parser, and only substitutions are performed. Sure! ![]() |