Welcome Guest, Not a member yet? Register   Sign In
php + view syntax mixed templates
#1

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
Reply
#2

As far as I'm aware that appears to be by design, there is a {noparse} tag but I'm unsure what that does.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#3

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;
}
Reply




Theme © iAndrew 2016 - Forum software by © MyBB