Solved

pass var to php from smarty

Posted on 2013-02-06
7
321 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 
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 51

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
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 look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

623 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