|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
kk Smarty Rookie
Joined: 10 Aug 2010 Posts: 22
|
Posted: Fri Jun 28, 2013 9:10 am Post subject: Syntax for include |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Jun 28, 2013 1:34 pm Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Jun 28, 2013 1:43 pm Post subject: |
|
|
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 |
|
kk Smarty Rookie
Joined: 10 Aug 2010 Posts: 22
|
Posted: Fri Jun 28, 2013 4:22 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Jun 28, 2013 4:51 pm Post subject: |
|
|
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 |
|
|
|
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
|