Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Overview - the template system

#1
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!

Reply


Messages In This Thread
Overview - the template system - by Darth-Apple - February 28th, 2014 at 7:38 PM
RE: Overview - the template system - by Acko - March 1st, 2014 at 3:33 AM
RE: Overview - the template system - by Darth-Apple - March 3rd, 2014 at 6:15 PM
RE: Overview - the template system - by Darth-Apple - March 3rd, 2014 at 9:56 PM



Users browsing this thread: 2 Guest(s)

Dark/Light Theme Selector

Contact Us | Makestation | Return to Top | Lite (Archive) Mode | RSS Syndication 
Proudly powered by MyBB 1.8, © 2002-2024
Forum design by Makestation Team © 2013-2024