Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Relative {include} problem after upgrade

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


Joined: 16 Feb 2016
Posts: 4

PostPosted: Tue Feb 16, 2016 4:36 pm    Post subject: Relative {include} problem after upgrade Reply with quote

I've been using 3.1.21-dev on one project for a long time and I decided to upgrade to what's current 3.1.29 and I ended up with the following when try to include template from with a sub-dir.
Code:
Uncaught --> Smarty: Unable to load template file './list.tpl' in 'file:_master.tpl'
Here is my folder structure:
Code:
tempaltes/
  listing/
      index.tpl
      list.tpl 
  _master.tpl

what has changed is with the older version I would get error in file:listing/index.tpl for example if I try to include non-exising file
Code:
Uncaught --> Smarty: Unable to load template file './non_exisint_file.tpl' in 'file:listing/index.tpl'
where I now get error in file:_master.tpl and this basically is why the new version is not working for me.
Here is sample of listing/index.tpl
Code:
{extends file="_master.tpl"}

{block name="body"}
   {include file="./list.tpl"}
{/block}

I use $smarty->display("listing/index.tpl");
What has changed and how do I overcome this?
Thanks Rolling Eyes
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1568

PostPosted: Tue Feb 16, 2016 6:33 pm    Post subject: Reply with quote

Include files with paths relative to templates directory.
I.e. listing/list.tpl
Or, better yet, use {extends} over {include} where possible.
Back to top
View user's profile Send private message
nforced
Smarty n00b


Joined: 16 Feb 2016
Posts: 4

PostPosted: Tue Feb 16, 2016 6:43 pm    Post subject: Reply with quote

Yes, this solves the problem but I still wonder why. For example here http://www.smarty.net/docs/en/language.function.include.tpl#idp35776976 second row is
Code:
{include './template-in-same-directory.tpl'}
and other than that this has been working that way and now for no reason it doesn't.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1568

PostPosted: Tue Feb 16, 2016 9:04 pm    Post subject: Reply with quote

It was a bug.
Back to top
View user's profile Send private message
nforced
Smarty n00b


Joined: 16 Feb 2016
Posts: 4

PostPosted: Wed Feb 17, 2016 10:45 am    Post subject: Reply with quote

AnrDaemon wrote:
It was a bug.

What do you mean by "was" like you find it and fixed it? I am talking about 3.1.29
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1568

PostPosted: Wed Feb 17, 2016 6:24 pm    Post subject: Reply with quote

The way it worked was a bug. Now it is fixed, and it no longer works in the wrong way.
Look yourself at what you've posted.
You're including "./template-in-same-directory.tpl" from "listing/index.tpl", which means you want to include "listing/template-in-same-directory.tpl". Obviously, there's no such file and include is failing.
Back to top
View user's profile Send private message
nforced
Smarty n00b


Joined: 16 Feb 2016
Posts: 4

PostPosted: Wed Feb 17, 2016 6:28 pm    Post subject: Reply with quote

I see, well this can be a bit misleading. For example when I try to include something inside listing/index.tpl same directory to me means the same directory where index.tpl is.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1568

PostPosted: Wed Feb 17, 2016 6:33 pm    Post subject: Reply with quote

Just don't use relative paths. Ever.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3 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