kratsg Posted November 1, 2007 Share Posted November 1, 2007 We all understand the concept of accessibility and usability based on numerous different sites to have a certain script. That said, we also know Smarty is a mean, extreme template engine that makes life easy in some cases. If I wanted something simple such as just replacing variables within a template (even if it was just an html table), what would be the best option? For example: I have one where based on the group, different group panels display (some groups see other groups as well as their own). If I had a template that looked like this: grouplinks.tpl.php <table border='1' width='75%' cellpadding='0' cellspacing='0' style='text-align:center;' align='center'> <tr><td width='100%'><b>{$header}</b></td></tr> //the rows after are built based on array values using a loop <tr><td width='100%'>{$data}</td></tr> //the rows are built based on array values using a loop </table> How do I manage something like this? Where {$header} gets replaced with the corresponding header and you automatically loop placing the data in? What I want this to be applied to is a flat-file based ACP (using .htaccess, .htgroup, .htpasswd files) for user-login and management, group management, and template management (template of the ACP itself). I don't know how to NOT use Smarty for templating, as you need to install Smarty on the site that the ACP is on in order for templates to work... Link to comment https://forums.phpfreaks.com/topic/75684-templating-question-using-php-to-manage-templates/ Share on other sites More sharing options...
kratsg Posted November 4, 2007 Author Share Posted November 4, 2007 bump Link to comment https://forums.phpfreaks.com/topic/75684-templating-question-using-php-to-manage-templates/#findComment-384631 Share on other sites More sharing options...
kratsg Posted November 5, 2007 Author Share Posted November 5, 2007 bumpity Link to comment https://forums.phpfreaks.com/topic/75684-templating-question-using-php-to-manage-templates/#findComment-384747 Share on other sites More sharing options...
btherl Posted November 5, 2007 Share Posted November 5, 2007 I don't really understand what you are asking. Are you saying you want to create your own templating system which has the basic features of Smarty? Link to comment https://forums.phpfreaks.com/topic/75684-templating-question-using-php-to-manage-templates/#findComment-384764 Share on other sites More sharing options...
kratsg Posted November 5, 2007 Author Share Posted November 5, 2007 In a way, yes.. I wanna be able to stick it in my ACP code so that it has its own templating system. Link to comment https://forums.phpfreaks.com/topic/75684-templating-question-using-php-to-manage-templates/#findComment-384967 Share on other sites More sharing options...
trq Posted November 5, 2007 Share Posted November 5, 2007 While I don't believe in them, a simple templating engine is easy to create. Given the following template.... foo.html <html> <head> <title>{title}</title> </head> <body> <p>Hello {hello}</p> </body> </html> You could simply parse it using something like... <?php $title = 'foo'; $hello = 'bob!'; $file = file_get_contents('foo.html'); $file = str_replace(array('{title}','{hello}'),array($title,$hello), $file); echo $file; ?> As soon as you need to start implimenting loops and conditionals though it gets far more complex. Personally, I use php as my templating engine. Its bar far the quickest. Link to comment https://forums.phpfreaks.com/topic/75684-templating-question-using-php-to-manage-templates/#findComment-385028 Share on other sites More sharing options...
kratsg Posted November 6, 2007 Author Share Posted November 6, 2007 As soon as you need to start implimenting loops and conditionals though it gets far more complex. Personally, I use php as my templating engine. Its bar far the quickest. How so? What I was trying to accomplish with the ACP, is if someone who doesn't know PHP uses it, they shouldn't be able to affect the php file itself, but rather, an html template file with {variables} that php will recognize and replace. Link to comment https://forums.phpfreaks.com/topic/75684-templating-question-using-php-to-manage-templates/#findComment-385374 Share on other sites More sharing options...
Demonic Posted November 6, 2007 Share Posted November 6, 2007 Why not try this tutorial out: http://www.codewalkers.com/c/a/Display-Tutorials/Writing-a-Template-System-in-PHP/ Link to comment https://forums.phpfreaks.com/topic/75684-templating-question-using-php-to-manage-templates/#findComment-385380 Share on other sites More sharing options...
teng84 Posted November 6, 2007 Share Posted November 6, 2007 While I don't believe in them, a simple templating engine is easy to create. Given the following template.... foo.html <html> <head> <title>{title}</title> </head> <body> <p>Hello {hello}</p> </body> </html> You could simply parse it using something like... <?php $title = 'foo'; $hello = 'bob!'; $file = file_get_contents('foo.html'); $file = str_replace(array('{title}','{hello}'),array($title,$hello), $file); echo $file; ?> As soon as you need to start implimenting loops and conditionals though it gets far more complex. Personally, I use php as my templating engine. Its bar far the quickest. I or rather we use almost the same as thorpe's trying to say why use smarty etc... if you can make your own... Link to comment https://forums.phpfreaks.com/topic/75684-templating-question-using-php-to-manage-templates/#findComment-385381 Share on other sites More sharing options...
kratsg Posted November 6, 2007 Author Share Posted November 6, 2007 The point is that in order for smarty to work, a server has to have it installed... And I need to make any php script compatible with any server that has at least PHP, so I can't be like "SMARTY REQUIRED", so I need my own templating system. Link to comment https://forums.phpfreaks.com/topic/75684-templating-question-using-php-to-manage-templates/#findComment-385643 Share on other sites More sharing options...
trq Posted November 6, 2007 Share Posted November 6, 2007 Then, my example is a good place to start. However, as soon as you need to start using loops and conditionals within a template, the actual template system becomes far more complex to write than my simple example. If you don't need loops or conditionals something like my example will suffice. Otherwise, start writting. I'm not sure what you want from us. Link to comment https://forums.phpfreaks.com/topic/75684-templating-question-using-php-to-manage-templates/#findComment-385668 Share on other sites More sharing options...
btherl Posted November 6, 2007 Share Posted November 6, 2007 Or you can bundle smarty with your script. Link to comment https://forums.phpfreaks.com/topic/75684-templating-question-using-php-to-manage-templates/#findComment-386221 Share on other sites More sharing options...
kratsg Posted November 7, 2007 Author Share Posted November 7, 2007 Bundling Smarty doesn't sound too bad... How might one go about that? I mean, it doesn't sound as simple as just sticking Smarty and the script in one folder, I'm sure... What do you mean by that? Link to comment https://forums.phpfreaks.com/topic/75684-templating-question-using-php-to-manage-templates/#findComment-386225 Share on other sites More sharing options...
trq Posted November 7, 2007 Share Posted November 7, 2007 Smarty itself is just like any other php application. You just need to put it in the correct location on the server. Link to comment https://forums.phpfreaks.com/topic/75684-templating-question-using-php-to-manage-templates/#findComment-386231 Share on other sites More sharing options...
btherl Posted November 7, 2007 Share Posted November 7, 2007 It is that simple .. I would add a folder called "smarty" under your application folder. Then you will need to set the appropriate settings in your script to tell it where smarty is. Something like require_once('smarty/Smarty.class.php'); The only slightly messy part may be setting permissions on the folders smarty uses for caching and so on. Those will need to exist be writeable. And the other issue is that your bundled smarty will eventually become out of date. But at least you don't have to worry about future releases breaking your script PHP itself has quite a few third party libraries bundled with it, which is how it is able to compile with so many features without installing anything extra. Link to comment https://forums.phpfreaks.com/topic/75684-templating-question-using-php-to-manage-templates/#findComment-386251 Share on other sites More sharing options...
kratsg Posted November 7, 2007 Author Share Posted November 7, 2007 So it really is just moving those files around, hmm, interesting. I'll take note of this and check it out sometime tomorrow (let you know if it works, won't "solve" this JUST yet) Link to comment https://forums.phpfreaks.com/topic/75684-templating-question-using-php-to-manage-templates/#findComment-386268 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.