I’ve been writing a small framework for a blog system of mine, and I’ve come across a little problem. When my end-users write a template for the system, they have parameters like %title% to load a preset variable.
$tpl->setParam('title','my site');
//%% are appended elsewhere
This is all well and good, but I need a solution to load a query and show the results, so instead of users having to write their own queries each time, I can just use the “query” parameter to load the query.
Any help would be greatly appreciated.
What I want to do is have %article% load an article from my database.
Still not completely understandable.
1. Load the SAME article: do a MySQL query, get an article from it then simply pass it to a variable then do the same as you do.
2. Load different articles in order: I don’t really have a good solution here, but here is an idea. First, count the occurences of %article. Then perform a query and store articles in an array, only the %article’s occurence number times. If that number is higher, the code should do something to clean it up. Then, get the first article and perform
for($i=0;$i<$occurences;$i++){$page = str_replace("%article", $articles[$i], $page,1);}3. Load %article(id): You might want regex in this case, I think.