Makestation
Overview - the template system - Printable Version

+- Makestation (https://makestation.net)
+-- Forum: Creative Arts General Plaza (https://makestation.net/forumdisplay.php?fid=124)
+--- Forum: The Others (https://makestation.net/forumdisplay.php?fid=60)
+---- Forum: Community Archive (https://makestation.net/forumdisplay.php?fid=107)
+----- Forum: Filecave Development (https://makestation.net/forumdisplay.php?fid=79)
+----- Thread: Overview - the template system (/showthread.php?tid=852)



Overview - the template system - Darth-Apple - February 28th, 2014

As I've documented on the official thread for filecave so far, I've officially begun working on the template system. What I have so far is pretty simple, but it works. The goal is to allow HTML templates to be edited and rearranged without the need to edit any actual PHP. It will overall make retheming filecave much easier and much more flexible.

I've decided to put the lang system and the templates system together. Both template tags and lang tags pretty much work the same way. Unlike MyBB's template system, Filecave will require all template variables to be explicitly set. This is for security reasons, as it makes it much more difficult to exploit the template system when only variables that are intended to be set can be used. So, instead of something like "{$conf_URL}", you will see something like [@conf_url]" instead, which PHP will not automatically parse.

For example:

Code:
hello world, [@user]! <br />
Age: [@age].<br />
Occupation: [@occupation]. </br />
Interests: [@Interests] <br />

Would reveal something like:

Quote:hello world, Darthness!
Age: Unknown
Occupation: Restaurant worker
Interests: Lots of stuff!

In the PHP, template variables are set something like this:

Code:
    $templates->set("user", "Darthness");
    $templates->set("age", "Unknown");
    $templates->set("occupation", "Restaurant worker");
    $templates->set("Interests", "Lots of stuff!");
    echo $templates->parse("template_hello");

This has now been implemented into Filecave as an API, and I'm currently working on converting existing code into code that uses this system. I've been working hard to ensure that it performs well, but we'll see how well it works once it actually starts being used more heavily. I'm using str_replace instead of strtr, but the consequence of that is that, in making the lang packs readable and easier to code, I have to individually parse each entry into the correct format when the template engine is initialized. I'm not entirely sure how well it will work yet.

Either way, lang tags are also supported. For example,

Code:
[@lang_hello], [@user]! <br />
[@lang_age]: [@age].<br />
[@lang_occupation]: [@occupation]. </br />
[@lang_interests]: [@Interests] <br />

The above script would also parse. A sample language pack might look like this:

Code:
$lang = array();
global $lang;
$lang['hello'] = "Hello world";
$lang['age'] = "Age";
$lang['occupation'] = "occupation;
$lang['interests'] = "Interests";

Stay tuned for more info!


RE: Overview - the template system - Acko - March 1st, 2014

Great and intriguing stuff. Love it.


RE: Overview - the template system - Darth-Apple - March 3rd, 2014

Thanks!

The header/footer are now converted to use the template system. As for the rest, my goal is to begin that today. It will be a lot of work because not everything will work until everything is fully converted, but it will be a HUGE step in the right direction once this is complete. Once this is complete, you will be able to design new themes for filecave without editing any PHP whatsoever. Big Grin


RE: Overview - the template system - Darth-Apple - March 3rd, 2014

This is easily going to be one of the most in-depth implementations I will be working with regarding current code. In fact, I may only try to implement this with the most essential features for now, and simply recode the less essential ones later. The entire user registration and login system will also have to be recoded.

I'm thinking I will use file based CSS files and templates for now. MyBB, for example, stores data regarding templates and CSS in the database, which isn't a bad idea, but it's a pain to code all of that right now. So, for the sake of simplicity, each template will have its own file. I'll probably group templates into different folders to make them easier to find eventually as well.