Re: [SMARTY] personalization using smarty
| From: | Roman Neuhauser | Date: | Wed, 14 Aug 2002 15:13:19 +0000 |
| Subject: | Re: [SMARTY] personalization using smarty | ||
| References: | 1 2 3 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-5703@lists.php.net to get a copy of this message | ||
> Date: Wed, 14 Aug 2002 16:19:16 +0200
> From: Michał Krowiarz <michal@probasket.pl>
> To: Roman Neuhauser <neuhauser@bellavista.cz>
> Subject: Re[2]: [SMARTY] personalization using smarty
>
> Hello Roman,
Michal, I hope you don't mind me cc'ing the list.
> Wednesday, August 14, 2002, 2:01:33 PM, you wrote:
>
> > I guess that depends on the way you pull the snippets from the
> > backend. Can you post a short, selfcontained script?
>
> ---index.php---
> <?php
> require("Smarty.class.php");
> $modules_left = array();
>
> function getModules() {
> global $modules_left,$modules_right;
> connectdb();
> $sql = "SELECT * FROM pro_users_settings WHERE userID=1";
> $res = mysql_query($sql) or die(mysql_error());
> while( $row = mysql_fetch_array($res) ) {
> $m_left = explode("|",$row[1]);
> $m_right = explode("|",$row[2]);
>
> for( $i=0; $i<count($m_left); $i++ ) {
> $rez = mysqL_query("SELECT moduleTplPath FROM pro_modules WHERE
> moduleID='$m_left[$i]'");
> $odp = mysql_fetch_row($rez);
> $modules_left[] = $odp[0];
> }
> }
> }
>
> getModules();
>
> $tpl = new Smarty;
> $tpl->assign("modules_l",$modules_left);
> $tpl->display("../tpl/index.tpl");
>
> ?>
> ---end of index.php---
>
> ---index.tpl---
> <table width=780 align=center>
> <tr>
> <td width=160 valign=top>
> {section name=module_l loop=$modules_l}
> {$modules_l[module_l]}
> {/section}
> </td>
> </tr>
> </table>
> ---end of index.tpl---
>
> ---poll code in DB---
> {php}
> require './sympoll/booth.php';
> display_booth(4);
> {/php}
> ---end poll code in DB---
well, you're doing it wrong. :)
if you want to have the *contents* of your templates in a database,
you'll need to use a custom recource plugin (see
templates.from.elsewhere.html file in Smarty docs).
if you just want to allow your users to put their sites together
using the module *names*, you should use {include}, or, rather, a
custom template function wrapping a custom resource plugin.
> i found some new ways to do that, creating a template file for
> every registered user, save it on the server with a filename assigned
> to the apropriate user and when the user changes something in the
> layout, just recreate this file (for my website it could do, it may
> have no more than 200-300 users for now)
> i have another idea, just read about prefilters. if I put my template
> code in for example that way: <!--# {include file=file.tpl} #-->, then
> using prefilter strip those <!--# and #-->, i would get the tag i
> need: {include file=file.tpl} for smarty to compile. and here's
> another problem, how to stip them?
> if anyone has a better solution, i'm still waiting for it :)
yes, this would be basically just like eval(). just like
include 'file.php'
is quite a bit more effective than
eval(get_file_contents('file.php'))
a custom resource handler would be better for your goal. IMO.
HTH
--
FreeBSD 4.6-STABLE
5:00PM up 5 days, 4:55, 17 users, load averages: 0.00, 0.00, 0.00