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
#2
Great and intriguing stuff. Love it.
I mod Paradox games. Click here to see my many adventures in doing that.

"Join the Army, see the world, meet interesting people - and kill them"
Reply
#3
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

Reply
#4
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.

Reply




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