Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Assgine multiple values to a single variable?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
goffer
Smarty n00b


Joined: 24 Jan 2017
Posts: 3

PostPosted: Tue Jan 24, 2017 8:14 am    Post subject: Assgine multiple values to a single variable? Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Jan 24, 2017 9:48 am    Post subject: Reply with quote

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
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Tue Jan 24, 2017 9:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
goffer
Smarty n00b


Joined: 24 Jan 2017
Posts: 3

PostPosted: Wed Jan 25, 2017 5:23 am    Post subject: Reply with quote

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
View user's profile Send private message
goffer
Smarty n00b


Joined: 24 Jan 2017
Posts: 3

PostPosted: Wed Jan 25, 2017 5:27 am    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Jan 25, 2017 9:48 am    Post subject: Reply with quote

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
View user's profile Send private message
elpmis
Smarty Elite


Joined: 07 Jun 2007
Posts: 321

PostPosted: Sun Jan 29, 2017 11:14 am    Post subject: Re: Assgine multiple values to a single variable? Reply with quote

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 Wink

http://www.smarty.net/forums/viewtopic.php?p=62320
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP