View previous topic :: View next topic |
Author |
Message |
goffer Smarty n00b
Joined: 24 Jan 2017 Posts: 3
|
Posted: Tue Jan 24, 2017 8:14 am Post subject: Assgine multiple values to a single variable? |
|
|
Hello
I am new on smarty. i later use php $GLOBALS on my projects as a variable on template . now i migrating to smarty.
Now i can't do a simple,basic things that previously do on php :
Ex later on php i do:
Code: |
<?php
//include "somethings";
ob_start();
?>
<form action="./first_example.php" method="POST">
Name:<input type="text" name="name"/>
<input type="hidden" name="submitted" value="1"/>
<input type="submit"/>
</form>
<?php
$form = ob_get_clean();
if( isset($_POST['submitted']) ){
$GLOBAL['TEMPLATE']['content'] = "Ok you submitted<br/>";
$GLOBAL['TEMPLATE']['content'] .= "This is other line of string";
}else{
$GLOBAL['TEMPLATE']['content'] = "Sorry .please click submit button";
}
$GLOBAL['TEMPLATE']['title'] = "page title";
$GLOBAL['TEMPLATE']['content'] = "First Content Value";
$GLOBAL['TEMPLATE']['content'] .= "Second Content Value";
include "./main-template.php";
?>
|
now on smarty when i use
$smarty->assign("page_content",$welcome);
then i can't assign other string to "page_content" variable.
if assign other string to this variable i just get last assign value not all values
ex:
Code: |
$smarty->assign("page_content","Hello"); // i see hello
|
Code: |
$smarty->assign("page_content","Hello");
$smarty->assign("page_content","Other Line"); // i see Other line @NOTE: i want to see -->Hello Other Line
|
thanks.sorry for be long.[/code] |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Jan 24, 2017 9:48 am Post subject: |
|
|
Please read Smarty tutorials again.
As many times as necessary to never repeat this mistake again.
All you need is to include a respective subtemplate with your form. |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Tue Jan 24, 2017 9:10 pm Post subject: |
|
|
What does your Smarty-coded template look like?
I think you have in that template this variable {$page_content}.
You can assign other strings to other variables:
Code: | PHP code:
$smarty->assign("other_content","Other Line");
Template code:
{$other_content} |
|
|
Back to top |
|
goffer Smarty n00b
Joined: 24 Jan 2017 Posts: 3
|
Posted: Wed Jan 25, 2017 5:23 am Post subject: |
|
|
AnrDaemon wrote: | Please read Smarty tutorials again.
As many times as necessary to never repeat this mistake again.
All you need is to include a respective subtemplate with your form. |
How?
My PHP Code:
Code: |
<?php
require 'libs/Smarty.class.php';
$smarty = new Smarty;
ob_start();
?>
<form action="./first_example.php" method="POST">
Name:<input type="text" name="name"/>
<input type="hidden" name="submitted" value="1"/>
<input type="submit"/>
</form>
<?php
$form = ob_get_clean();
if( isset($_POST['submitted']) ){
$welcome = "Welcome ".$_POST['name'];
$smarty->assign("page_content",$welcome);
}else{
$smarty->assign("page_content",$form);
}
$smarty->assign("browser_title", "Hello Smarty!!");
$smarty->assign("page_title", "Home");
$smarty->assign("page_content", "<br/>Please fill above form");
$copyright = "Copyright".date('Y');
$smarty->assign("copyright", $copyright);
$smarty->display('index.tpl');
?>
|
my Smarty Templates:
header.tpl
Code: |
<head>
<title>{$browser_title}</title>
</head>
|
index.tpl
Code: |
<!DOCTYPE html>
<html lang="en">
{include file="header.tpl"}
<body>
<h1>{$page_title}</h1>
<p> {$page_content}
</p>
{include file="footer.tpl"}
</body>
</html>
|
footer.tpl
Code: |
<p>
<small>{$copyright}</small>
</p>
|
Now what i want is to see --->
Form & `Please fill above form`
like below image:
|
|
Back to top |
|
goffer Smarty n00b
Joined: 24 Jan 2017 Posts: 3
|
Posted: Wed Jan 25, 2017 5:27 am Post subject: |
|
|
bsmither wrote: | What does your Smarty-coded template look like?
I think you have in that template this variable {$page_content}.
You can assign other strings to other variables:
Code: | PHP code:
$smarty->assign("other_content","Other Line");
Template code:
{$other_content} |
|
Thanks. i know i can assignto other variable but then i must add other variable side of other variable like -->
in index.tpl file
Code: |
<p>
{$page_content}
{$also_page_content}
{$page_content_downer}
</p>
|
But it seems not goodway. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Jan 25, 2017 9:48 am Post subject: |
|
|
Make a form.tpl with your form template, include it where appropriate, and assign form values to Smarty object, if need.
You don't need to manually render form, much less - the way you've done it. |
|
Back to top |
|
elpmis Smarty Elite
Joined: 07 Jun 2007 Posts: 321
|
Posted: Sun Jan 29, 2017 11:14 am Post subject: Re: Assgine multiple values to a single variable? |
|
|
goffer wrote: | Hello
I am new on smarty. i later use php $GLOBALS on my projects as a variable on template . now i migrating to smarty.
Now i can't do a simple,basic things that previously do on php :
|
Please look here
http://www.smarty.net/forums/viewtopic.php?p=62320 |
|
Back to top |
|
|