Jump to content

Recommended Posts

Posted

Hello! I'm loving this CMS so far. I'd like to use a template to generate a KML file that can be included in other templates (as filename.kml, not as a dynamically generated page). Is there a way to do this? Thanks!

Posted

Your ProcessWire template files are just like any other regular PHP file, so you can do anything with them that you could with a PHP file on it's own. Since you are wanting to generate a static KML file, your main consideration will be to determine where you generate it. ProcessWire will create a writable files directory for any page, which you can get to by accessing the filesManager() function, like this:

$path = $page->filesManager()->path();
$url = $page->filesManager()->url();

So to generate the file, you'd do something like this:

$data = "say this is your KML data";
$filename = $page->filesManager()->path . "my-data.kml";
file_put_contents($filename, $data);

Then you could access that file from your browser at:

$page->filesManager->url() . "my-data.kml";

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...