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

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


Joined: 10 Aug 2010
Posts: 22

PostPosted: Fri Jun 28, 2013 9:10 am    Post subject: Syntax for include Reply with quote

Sorry if this was mentioned earlier or explained why this should be like that but maybe just an idea to improve 'readability' of the include tag.
Wouldn't it be nicer to exclude the resource type from the template resource path?
Code:
{include file='file:C:/www/pub/templates/header.tpl'}

equals
Code:
{include file='C:/www/pub/templates/header.tpl'}

which is allowed
and
Code:
{include file='db:header.tpl'}

could equal
Code:
{include db='header.tpl'}


This IMO would be more intuitive for designers/maintainers of templates.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7285
Location: Lincoln Nebraska, USA

PostPosted: Fri Jun 28, 2013 1:34 pm    Post subject: Reply with quote

If you don't include the resource (file:, db: , etc.) Then the default is assumed. "file:" is the default, unless you specify otherwise.

This:

{include db='header.tpl'}

Will cause an error, and Smarty won't know that "db" is the file resource. That syntax is reserved for passing variables into the included template. This is why the resource must be part of the path.

You can do something fancy with a prefilter if you really want that syntax. Or, set "db:" as the default resource and just use normal syntax for includes.
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


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

PostPosted: Fri Jun 28, 2013 1:43 pm    Post subject: Reply with quote

Note that the 'file=' is the attribute name and not the resource.

So your suggestion would not work and and break the syntax.

But could could use the shortag format (not using attribute names)

It woul look like this


Code:

{include 'C:/www/pub/templates/header.tpl'}

{include 'file:C:/www/pub/templates/header.tpl'}

{include 'db:header.tpl'}


See http://www.smarty.net/docs/en/language.function.include.tpl
Back to top
View user's profile Send private message
kk
Smarty Rookie


Joined: 10 Aug 2010
Posts: 22

PostPosted: Fri Jun 28, 2013 4:22 pm    Post subject: Reply with quote

Short form it is.

attribute name 'file' should change to 'resource' to avoid people like me getting confused.

Thanks for quick reply.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7285
Location: Lincoln Nebraska, USA

PostPosted: Fri Jun 28, 2013 4:51 pm    Post subject: Reply with quote

It has historically been file=, and makes sense for most purposes. PHP is just as confusing:

file_get_contents('http://www.google.com/');
Back to top
View user's profile Send private message Visit poster's website
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