|
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 |
ciatog Smarty n00b
Joined: 18 May 2012 Posts: 1
|
Posted: Fri May 18, 2012 4:02 pm Post subject: Include Template from Plugin in 3.1 |
|
|
Hey,
I'm in the process of upgrading to 3.1 from 2. I'm running into an issue in one of the project plugins that's using the following function: _smarty_include (It takes the name of a template and an array of parameters).
I understand this is an internal function from version 2 but is there a way to do this in 3.1?
Thanks for your help |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri May 18, 2012 4:56 pm Post subject: |
|
|
Code: | smarty_function_foo($params, $template) {
....
$content = $template->smarty->fetch('foo.tpl');
return $content;
}
|
|
|
Back to top |
|
moroz1999 Smarty Rookie
Joined: 02 Mar 2011 Posts: 5
|
Posted: Thu May 31, 2012 2:51 pm Post subject: |
|
|
I needed to replace the standard Smarty "include" functionality with my own and found, that I don't know how to pass the parameters.
This is how I did it:
Code: | public function myInclude($params, $parentTemplate)
{
if (isset($params['file']))
{
$templatePath = $params['file'];
if (is_file($templatePath))
{
$template = $parentTemplate->createTemplate($templatePath, null, null, $parentTemplate);
foreach ($params as $parameter=>&$value)
{
$template->assign($parameter, $value);
}
return $template->fetch();
}
}
return false;
} |
Isn't there a simplier way? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu May 31, 2012 9:41 pm Post subject: |
|
|
If all depends for what reason you can't use {include}? |
|
Back to top |
|
moroz1999 Smarty Rookie
Joined: 02 Mar 2011 Posts: 5
|
Posted: Sun Jun 03, 2012 1:09 pm Post subject: |
|
|
I began to answer the question and I understood that I didn't really needed to use my own function for an inclusion.
I wanted to implement some additional logics of design themes hierarchy. I understand now that this logics can be placed into external object to use it somehow like that:
{include file=$myTheme->getTemplatePath("mytemplate.tpl")} |
|
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
|