Multiple usage of one template within one page
| From: | ON.KG | Date: | Wed, 10 Nov 2004 08:31:38 +0000 |
| Subject: | Multiple usage of one template within one page | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-11953@lists.php.net to get a copy of this message | ||
Hi!
I have template of form. Result of this template depends on data,
which it gets from assignment from my script:
Examples:
page_body.tpl
-------- Starts
<html>
<head>
......
</head>
</html>
<body>
{include file="$first_form"}
{include file="$second_form"}
</body>
</html>
-------- Ends
form.tpl
-------- Starts
<form method="post" action="{$form_action}" name="{$form_name}"
{$form_attributes}>
{* Form Elements *}
{section name=form loop=$form_elements}
<input type="{$form_elements[form].type}"
name="{$form_elements[form].name}"
value="{$form_elements[form].value}">
{/section}
</form>
-------- Ends
form.php
-------- Starts
<?php
include("Smarty.class.php")
$tpl = new Smarty;
.................
// First Form
$tpl->assign(array(
'form_action' => $PHP_SELF,
'form_name' => 'form1',
......
'form_elements' => $form_elements
));
$tpl->assign('first_form', 'form.tpl');
// Second Form
$tpl->assign(array(
'form_action' => 'other.php',
'form_name' => 'form2',
......
'form_elements' => $form_elements2
));
$tpl->assign('second_form', 'form.tpl');
$tpl->display('page_body.tpl');
?>
-------- Ends
Output:
-------- Starts
<html>
<head>
......
</head>
</html>
<body>
<form method="post" action="other.php" name="form2">
<!-- List of element of SECOND (!) Form -->
...
</form>
<form method="post" action="other.php" name="form2">
<!-- List of element of SECOND (!) Form -->
...
</form>
</body>
</html>
-------- Ends
It displays TWO same forms, which defined at second time in my 'form.php'
How to make this work correctly - I need to get TWO different forms on one page
Thanks!