This might seem really obvious but its not too me and I am looking to do something similar to what im trying to do.
Consider the following file -> sample.phtml
which contains:
hello world.
If I do: $a = require_once('sample.phtml');
hello world
is not captured in $a
, instead the return value of require_once (in this case 1) is, and the contents of the file is echoed out to the screen.
What I am trying to do in what I call template injection. I want to capture the value of a template - html and all to then echo out into another template at some specific point.
So assume I have a template of:
<div>
... fancy jazz
<?php echo $a; ?>
</div>
It is assumed that $a
is whats called a view variable, that is a variable thats passed into the view via doing something like:
$$a = $a
I believe this considered a global variable?
Any how this is impossible because the contents of $a
, are echoed above the content of the template, in this case above the top <div>
.
Is there any way to do what I am trying to do?