Jump to content

Use both local and external templates


PHPSpert
 Share

Recommended Posts

Ok, this might be a little unique, not sure.

Basically, I have already accomplished getting PW to use an external path to another domain to grab a directory of global templates I need for this app I'm creating.

But now, I also want to allow clients to have local templates. So what I want to do is allow Processwire to search both the local templates dir and the global one on the other domain.

Is there a way to do this? There's only one path, but is it possible to include from two paths without re-coding a bunch?

Link to comment
Share on other sites

I don't know of a way to have ProcessWire keep track of two separate template directories. But of course you can turn any template file into a controller for any number of other template files and include them from wherever you want. A simple example would be to create a template called "external" and add a text field to it called "external_file". Then in your external.php:

<?php
if($page->external_file) {
 $filename = "/some/external/path/" . $sanitizer->name($page->external_file) . ".php";
 if(is_file($filename)) include($filename);
   else echo "$filename does not exist"; 
} else {
 echo "No external file defined"; 
}

Rather than external_file being a text field, it'd be better as a page reference field connected to a <select>. That way you could select your template rather than having to type it in. But I wanted to keep this example as simple as possible.

  • Like 2
Link to comment
Share on other sites

I don't know of a way to have ProcessWire keep track of two separate template directories. But of course you can turn any template file into a controller for any number of other template files and include them from wherever you want. A simple example would be to create a template called "external" and add a text field to it called "external_file". Then in your external.php:

<?php
if($page->external_file) {
$filename = "/some/external/path/" . $sanitizer->name($page->external_file) . ".php";
if(is_file($filename)) include($filename);
else echo "$filename does not exist";
} else {
echo "No external file defined";
}

Rather than external_file being a text field, it'd be better as a page reference field connected to a <select>. That way you could select your template rather than having to type it in. But I wanted to keep this example as simple as possible.

Wow - Yes, that's one way to do it.

Thanks Ryan, you're a genius.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...