Reputation: 354
I am attempting to convert a coldfusion base site template that I use everyday in coldfusion to php.
In coldfusion I have a cfsavecontent that holds a block of data that I display.
here is an example:
<cfoutput>
<cfsavecontent variable="content">
<div class="container-fluid content">
<h3>Hello World</h3>
</div>
<cfinclude template="modal/modal.cfm">
</cfsavecontent>
</cfoutput>
<cfinclude template="includes/template.cfm">
What would be the php version of cfsavecontent. Or is it even possible?
Thanks.
Upvotes: 2
Views: 700
Reputation: 29870
Given this CFML:
<cfsavecontent variable="content">
Some text<br>
<cfif randRange(0,1)>
<cfset result = "value if true">
<cfelse>
<cfset result = "and if it's false">
</cfif>
<cfoutput>#result#</cfoutput><br>
Message from include is:
<cfinclude template="./inc.cfm">
</cfsavecontent>
<cfoutput>#content#</cfoutput>
And the include:
<cfset greeting = "G'day">
<cfoutput>#greeting#</cfoutput><br>
A PHP analogue would be:
<?php
ob_start();
echo "Some text" . PHP_EOL;
if (rand(0,1)){
$result = "value if true";
}else{
$result = "and if it's false";
}
echo $result . PHP_EOL;
echo "Message from include is: ";
include __DIR__ . "\inc.php";
echo ob_get_clean();
inc.php:
<?php
$greeting = "G'day";
echo $greeting . PHP_EOL;
So you want to look at "Output Control Functions" in the docs.
Upvotes: 8