Home > Archive > PHP Language > January 2006 > Variable replacement
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Variable replacement
|
|
| lotusny78@yahoo.com 2006-01-10, 4:00 am |
| 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.
Thanks and Happy Holidays!!!
-Sean
| |
| Marcel Schindler 2006-01-10, 4:00 am |
| 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/
| |
| Connector5 2006-01-10, 4:00 am |
| 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:
>
> 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/
| |
| Jim Michaels 2006-01-16, 9:55 pm |
| The question was unusual. I didn't think you could put PHP in a .html file.
The web server would simply show your source code. If I am wrong, what's
smarty?
"Connector5" <junkmilenko@charter.net> wrote in message
news:2t1sf.5354$5R3.2055@fe02.lga...
> 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...
>
>
|
|
|
|
|