Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Include Template from Plugin in 3.1

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    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: 5068
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 Rookie


Joined: 02 Mar 2011
Posts: 5

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: 5068
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 Rookie


Joined: 02 Mar 2011
Posts: 5

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:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    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