You are here: Re: Variable replacement « PHP Language « IT news, forums, messages
Re: Variable replacement

Posted by Connector5 on 12/27/05 04:15

Marcel is right. Your method of using the templates diminishes the purpose
of smarty. You are closer to rolling your own templation solution than you
are to using a smarty solution.

But if you must know:

$file = file_get_contents('logingbody.html');
$file = str_replace('$blahblah', 'new value for $blahblah', $file);
$smarty->assign ...

When using your own variables, I recommend encapsulating them in braces to
help aleviate misparsing:
$file = str_replace('{$blahblah}', 'new value for $blahblah', $file);

But if you are going to encapsulate like that, you might as well rename
loginbody.html to loginbody.tpl and use $smarty->display('loginbody.tpl');







"Marcel Schindler" <info_NOSPAM_@trancefish.de> wrote in message
news:43b06ade$0$4001$9b622d9e@news.freenet.de...
> lotusny78@yahoo.com schrieb:
> > Hi all,
> > I'm using Smarty to template my pages. I'm bringing in the HTML of the
> > <body> in the statement:
> > smarty->assign("body", file_get_contents("loginbody.html"));
> > where loginbody.html contains a form and some text.
> >
> > Challenge: how can I set a variable in the html file?
> >
> > What I want to accomplish (the following doesn't work):
> > //login.php
> > $target = $_GET['target'];
> > smarty->assign("body", file_get_contents("loginbody.html"));
> >
> > //loginbody.html
> > <form ... action="login.php?target=$target"... >
> >
> > Motivation:
> > The login page reloads itself after a form has been filled out to check
> > the login. login.php is originally called with the
> > page-to-navigate-to-after-login passed as a GET, so this must be
> > forwarded to the second request for login.php.
> >
>
> Hey Sean,
>
> I never worked with Smarty, though it could be possible, that my answer
> is totally wrong but I think, you misunderstood the template-stuff:
>
> With Templates you do not have PHP and HTML together in one file. There
> is a program and there is the design. What you do with
> $smarty->assign('body',[...]) is wrong. You have to load the
> "loginfile.html" AS a template, not IN a template.
>
> I will not give you a course about Smarty in general but you'll have to
> check the whole manual at http://smarty.php.net/ again.
>
> --
> http://www.trancefish.de/
> http://www.skaletracker.de/

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация