Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Include Template from Plugin in 3.1

 
Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
ciatog
Smarty n00b


Joined: 18 May 2012
Posts: 1

PostPosted: Fri May 18, 2012 4:02 pm    Post subject: Include Template from Plugin in 3.1 Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4636
Location: Hamburg / Germany

PostPosted: Fri May 18, 2012 4:56 pm    Post subject: Reply with quote

Code:
smarty_function_foo($params, $template) {
    ....
    $content = $template->smarty->fetch('foo.tpl');
    return $content;
}

Back to top
View user's profile Send private message
moroz1999
Smarty n00b


Joined: 02 Mar 2011
Posts: 2

PostPosted: Thu May 31, 2012 2:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4636
Location: Hamburg / Germany

PostPosted: Thu May 31, 2012 9:41 pm    Post subject: Reply with quote

If all depends for what reason you can't use {include}?
Back to top
View user's profile Send private message
moroz1999
Smarty n00b


Joined: 02 Mar 2011
Posts: 2

PostPosted: Sun Jun 03, 2012 1:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP