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

[solved]Registering custom template resource

 
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
Tim M.
Smarty n00b


Joined: 27 Mar 2015
Posts: 3

PostPosted: Fri Mar 27, 2015 10:35 am    Post subject: [solved]Registering custom template resource Reply with quote

EDIT: Solved. I had to give $source an uncompiled template.

Hello,

im pretty new in smarty developement and I am working on template inheritance. I have a template that extends another. This template is in an other directory than my main template folder so I want to extend it like this:

Code:
{extends file="parent:index.tpl"}


I know how to register a new ressource and for now I can compile the requested template and return it. I did it by the following code:

Code:
class Smarty_Resource_Parent extends Smarty_Resource_Custom
{

    protected function fetch($name, &$source, &$mtime)
    {
        $source = Awe::Tpl()->compile($name);
        // Awe::Tpl() refers to my smarty class
    }

}


Pretty simple code and it works.. but not as I want. As test I put a block into my parent template that I want to extend and a second block, same name in the template with I wanna extend my main template. But nothing changes in the main template.

I am sure that my solution can't be right and I am happy for every suggestions from you.

Thank you all,
Tim


Last edited by Tim M. on Fri Mar 27, 2015 12:08 pm; edited 1 time in total
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Mar 27, 2015 12:06 pm    Post subject: Re: Registering custom template resource Reply with quote

Tim M. wrote:

$source = Awe::Tpl()->compile($name);
// Awe::Tpl() refers to my smarty class

Do you have modified compiler? No? Then why in the nine burning hells you are not calling Smarty::compile?

But your problem is not here.
Your problem is that you should have added both directories as template sources and not use any custom plugins whatsoever.
Back to top
View user's profile Send private message
Tim M.
Smarty n00b


Joined: 27 Mar 2015
Posts: 3

PostPosted: Fri Mar 27, 2015 12:10 pm    Post subject: Reply with quote

Nah, compile is just a synonym for fetch.

Works fine since I just read the raw template file into $source.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sat Mar 28, 2015 1:22 am    Post subject: Re: [solved]Registering custom template resource Reply with quote

Tim M. wrote:


im pretty new in smarty developement and I am working on template inheritance. I have a template that extends another. This template is in an other directory than my main template folder so I want to extend it like this:

Code:
{extends file="parent:index.tpl"}




You must not use a custom resource to access templates from different folders.
With Smarty::setTemplateDir() you can provide an array of template folders. Smarty will traverse the directories and stop on the first matching template found.
See http://www.smarty.net/docs/en/api.set.template.dir.tpl and http://www.smarty.net/docs/en/variable.template.dir.tpl
Back to top
View user's profile Send private message
Tim M.
Smarty n00b


Joined: 27 Mar 2015
Posts: 3

PostPosted: Mon Mar 30, 2015 6:30 am    Post subject: Reply with quote

That's exactly the reason why I registered a new resource. But anyway, thank you.
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