Solved

pass var to php from smarty

Posted on 2013-02-06
7
314 Views
Last Modified: 2013-05-11
--- in smarty file

 include {php}include_once("content/somefileicreate.php"){/php}
{$product.id}    --- this will show eg. 125

--- in php file
i try $id = $product.id;
......... and final return $id1

but the result of $id1 is smarty will become "id"

how am i pass a var to php file from this smartyfile??
0
Comment
Question by:john80988
7 Comments
 

Author Comment

by:john80988
ID: 38859576
how am i pass variable say $pid to include file of php {php} include("/pathtophp/a-program.php"){/php}
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 38861655
Smarty is very complicated.  Smarty is kind of a compiled template engine.  I never figured out how to change basic PHP statements by themselves.  It's not intended to work that way.  

All I can suggest is that you learn more about it.  http://www.smarty.net/   I won't work on Smarty or Xoops web sites.
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 38861780
@john80988 , You are going to have to post a little more code showing how you are doing this.

@DaveBaldwin, I didn't find your post very useful to the OP at all.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38861817
Eddie, I suspect that you have never worked on a Smarty template.
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 38861942
Oh, yes, plenty. While I agree with your opinion about Smarty, I can't understand why anyone would want to learn yet another language, I just wouldn't tout it when he already is using Smarty.

Smarty had it's time and place and today there are much better ways of doing things.

john80988 didn't post enough code to give a definitive answer, however.
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 38861960
I second DaveBaldwin's comment.  Smarty is a nightmare, and the best advice any of us could give the OP is to begin migrating away from it.

Smarty is a templating system designed to allow application code to exist in PHP, and the presentation code to exist in HTML.  The two are not supposed to meet up, except by way of the Smarty engine.  In its role as the middle-man, the communication is primarily one-way - the HTML portion of the template normally runs *after* the "standard" PHP has finished its work.  Using Smarty to pass values back to PHP does not make sense in this context, if it is even possible (I'm unsure if it is or not).  

In reality, Smarty merely abstracts the problem of mixing logic with presentation, adding its own middle-man syntax.  When you create a Smarty site, you ARE mixing logic and presentation.  It's just that the logic is now Smarty directives instead of PHP commands.  It adds very little benefit, at the cost of Smarty's learning curve and complexity, and general lack of community support.  All the developers I know shun Smarty like a pedophile at a birthday party.

If you must absolutely use Smarty, I suggest using it as little as possible, and then only as intended - to push finished data into your HTML template.  My primary goal would be to remove Smarty from the equation where ever possible.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38862162
Then Eddie, if you can help him, I salute you.  I just felt compelled to give him a warning at the very outset.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question