Is it possible to use an include file inside of a Heredoc (EOD)? We are using a variable to define the page and cant open and close the EOD to put in the include. All it does is echo the include as text only. I know you can use a variable and we tried to use a variable and place the include inside that but it just echos the include as text again. Here is a sample of what it is:
$view=<<<EOD
all of our code that needs to be in view
include('navigation.php');
all of the code that still has to be in view
EOD;
Is it possible to use an include file inside of a Heredoc (EOD)?
Nope.
Get rid of this ancient heredoc.
Make a PHP file with all the view data.
Do all your script logic. And then include your view file
e.g.
page.php
<?
$title="Sample";
include "view.php";
?>
view.php
<html>
<title><?=$title?></title>
all of our code that needs to be in view
<? include('navigation.php'); ?>
all of the code that still has to be in view
</html>
or use any other template engine, but your navigation must be done using same template engine, not direct output.
//utility function
function getIncludeContents($included_file_path){
ob_start();
include($included_file_path);
$contents = ob_get_contents();
ob_end_clean();
echo $contents;
}
//usage
$navigation = getIncludeContents('navigation.php');
$view = <<<EOD
all of our code that needs to be in view
$navigation
all of the code that still has to be in view
EOD;