axtg86 Posted July 1, 2009 Share Posted July 1, 2009 Hi all, I'd like to ask for your input and ideas on the following: I've got a back-end system managing a websites content. It has a default index.php file with variable holders such as $title, $content, etc which are set by an included file depending on the ?page= querystring. So if ?page=home then the include looks up the DB and fills the variables. All fine, but now I'd like to use different "templates" for both an English variant and Dutch variant. Perhaps even more are to be added later. How can I still use one index.php with the current include feature but have different templates applied to it based on a database variable for a certain page? Imagine the page home-nl and home-uk being requested (index.php?page=home-nl or index.php?page=home-uk). The include file finds for home-nl $row['variant']=nl. In this case the template applied to the index.php should be nl(.html) with Dutch texts, a Dutch menu, etc but still have $title and $content inserted. I've tried this for index.php (see below), but stream_get_contents() doesn't parse (of course) PHP. I realize this is a bit "out there", and it might never be answered. But never hurts trying, right ? Thanks! <?php require_once('./lib/contentfill.php'); if ($stream = fopen("./lib/templates/".$row['variant']."/index.php", 'r')) { $stream = stream_get_contents($stream); $tag = array($content, $title); $data = array($row['content'], $row['title']); $contents = str_replace($tag, $data, $stream); echo $contents; } ?> Link to comment https://forums.phpfreaks.com/topic/164364-template-routing/ Share on other sites More sharing options...
Adam Posted July 1, 2009 Share Posted July 1, 2009 There's a few methods of doing this (search the forums for past topics for more information on them). With your setup what I'd do personally rather than having separate HTML files for each language, which obviously means editing 2 files whenever you change the structure of the page, I'd implement a SMARTY style tag that you can encase around any text to be translated. So you'd have a kind of master file in English, then depending upon a param passed in the URL (e.g. "lang=nl" you can look up the translation in the specified language. So say {t}hello{/t} would translate into "Hallo" (I think, I don't know Dutch). Link to comment https://forums.phpfreaks.com/topic/164364-template-routing/#findComment-867046 Share on other sites More sharing options...
axtg86 Posted July 2, 2009 Author Share Posted July 2, 2009 Hi, Thank you for your suggestions. I'll surely try to search the forums for "template routing" and such terms. Since you indicated your personal favor I'd like to ask you for your preference when actually using two different HTML files. I'm considering this, since in the end I might use the same technique for different templates as well (based on e.g. depth). Thanks! Xander. P.s.: Hello in Dutch is indeed Hallo . Link to comment https://forums.phpfreaks.com/topic/164364-template-routing/#findComment-868024 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.