|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
pirk.lajos Smarty n00b
Joined: 22 Apr 2009 Posts: 2
|
Posted: Wed Apr 22, 2009 12:17 pm Post subject: {include_php} passing parameters is possible |
|
|
At 1st, sorry about my engish skill.
So, i had some problem about passing params in the function {include_php}.
After i just realized, the smarty engine work with plus params, just don give those to the php. So i modified the Smarty.class.php. There is a function, called "_include". So in this function, u still have the other params from the {include_php}. You need to put this 1 line here:
$_POST['passed_params'] = $params;
to looks like:
function _include($filename, $once=false, $params=null)
{
$_POST['passed_params'] = $params;
if ($once) {
return include_once($filename);
} else {
return include($filename);
}
}
After this:
in the php file what you want to inlude, you can get an array, what have all of your passed params.
Example:
tpl file:
{include_php file="example.php" param1="example param"}
php file:
$smarty->assign('param1',$_POST['passed_params']['param1']);
I hope, u can use this tip.
Kind regards:
Lajos Pirk
Hungary |
|
Back to top |
|
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Wed Apr 22, 2009 6:34 pm Post subject: reconsider to change your scripts |
|
|
Hi,
You can use {include_php}.
But please consider not to use it again.
Just assume that Smarty does not support have things like include_php tags.
It is because, violates a template design and jumps back to php programming. Included PHP file can access all the variables, but those ones defined in other files must we accessed as global variables.
Super global variables ($_POST, $_GET, ...) can be access and assigned from anywhere. Just take care of the other variables.
While you are using inlude / include_once, it jumps away from smarty template folder to native php folder (from where the file is being browsed), so you may get unpleasant reasons. And, anything you can do with {include_php}, you can do with simple php too, without the Smrarty being used.
Hence, for not continuing the confusion, discard the use of {include_php} for making a good Smarty template. |
|
Back to top |
|
pirk.lajos Smarty n00b
Joined: 22 Apr 2009 Posts: 2
|
Posted: Wed Apr 22, 2009 9:06 pm Post subject: I know what u want |
|
|
But.
I know, i can access for super global varibles (get, post session etc.) from anywhere, but i need this kind code, because, i use the same php file for some components on my website.
Example, i have a component, what display 1pc news.
I use this 1 php at 3 times for display 3 different news on the left side of my portal. so, i call that php with include_php and passing the news id for it.
I hope you understand what i mean. (coz of my bad english)
King regards,
Lajos Pirk
Hungary |
|
Back to top |
|
|
|
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
|