Solved

pass var to php from smarty

Posted on 2013-02-06
7
309 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 82

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 82

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 82

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now