php + view syntax mixed templates - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: php + view syntax mixed templates (/showthread.php?tid=81588) |
php + view syntax mixed templates - jacobs-kmi - 03-21-2022 Hello All, I've been porting our application from CI 3 to CI 4 and found from the documentation that the CI4 template parser seems to expect that no php within the template file. In CI 3 mixed view files with php and template syntax {variables} {variable} {/variables} were perfectly fine, however the CI3 to CI4 migration docs don't mention that this depth of porting would be required. Am I just missing something, or are you really not able to have PHP and template syntax within a view file in CI4? Thanks in advance! -Raymond RE: php + view syntax mixed templates - ignitedcms - 03-21-2022 As far as I'm aware that appears to be by design, there is a {noparse} tag but I'm unsure what that does. RE: php + view syntax mixed templates - jacobs-kmi - 03-23-2022 Thanks for that info! It seems like an unfortunate design choice; especially given that folks might be coming from CI3 with mixed views; but in any case I have found a workaround which so far is working well. I'm unsure if it solves all scenarios but we'll see. Here is the simple example where I first use the view renderer to eval the php template to a string, and then pass that string through the view parser. function viewParsed($ci_url, $data = []){ $renderer = service('renderer'); $parser = service('parser'); $r1 = $renderer->setData($data)->render($ci_url); $r2 = $parser->setData($data)->renderString($r1); return $r2; } |