I'm in a weird place with this new project: I have a client with a working Javascript application and they want to manage the text elements with a CMS. The native JS environment would be leading.
Ideally, EE would manage content and then render to static files in a content directory. I'm not a PHP guy and my experience with EE content has always been dynamic, using it's tags. Now I need to pre-render the content to a file or url, outside the template directory...so I could use some guidance.
Something like this works:
{exp:channel:entries
channel="content"
disable="categories|category_fields|member_data|pagination|trackbacks"
status="Open"
dynamic="no"
limit="1"
}
<?php
$File = "./articles/YourFile.html";
$Handle = fopen($File, 'w');
$Data = "<h1>{title}</h1>\n<hr /><p>{base_body}</p>\n";
fwrite($Handle, $Data);
print "Data Written";
fclose($Handle);
?>
{/exp:channel:entries}
But I actually have to manually view the page to render content... is there a way around this? Can I use EE as an service? An example on how to render the above content would be helpful..I'm getting my head around services today too..
This is what I've set up previously to get a static file of an EE template.
I setup my EE template like normal. Then set up a PHP script which uses CURL to call the template URL and write the contents to a static file. I set up a cron to run the file at the interval I need.
The PHP script file and the output PHP or TXT file (or whatever you need it to be named) are in the same directory. Make sure the output file has 777 permissions.
This is what you would put in the php script file. Just change the $site and $filename variables to what you want to use:
set_time_limit(3450);
#GRAB DATA
$site = "http://www.domain.com/template-group/template";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$site);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);
#WRITE DATA TO FILE
$filename = 'static-file-name.php';
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'w')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $result) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, updated the accordion file";
fclose($handle);
} else echo "The file $filename is not writable";
Your EE template would look like this:
{exp:channel:entries channel="content" disable="categories|category_fields|member_data|pagination|trackbacks" status="Open" dynamic="no" limit="1" }
<h1>{title}</h1>
<hr />
<p>{base_body}</p>
{/exp:channel:entries}