Smarty3: getting rid of $ in templates to allow every xhtml page to be a template

9 views
Skip to first unread message

Snaky Love

unread,
Feb 11, 2009, 6:47:42 AM2/11/09
to Smarty Developers
Hi,

I was using Smarty some years now and I believe it is a good tool. I
would like to discuss an idea about templating and hope the discussion
about upcoming Smarty3 is not to advanced by now.

I believe it will open some doors to more flexible handling of large
amounts of templates / content and also very interesting applications
if there was no $ in template variables. I think it is a good idea to
use TAGS for markup of variables in a tag-based markup language and
not variables like in programming language syntax. Mixing paradigms
here closes the doors to some interesting applications unneccessarily.

The idea is to make *every* xhtml or xml file a possible template for
your application - get it? This would completely eliminate the step of
creating a separate set of template files.

Variables should be defined by class ids or any kind of valid xhtml
tags and *everything inside the tag* is the variable to be replaced.
Imagine a soap or restful application that just "knows" which tags to
replace with your content. Some steps further a lot of "intelligent"
applications could be achieved that way (selfgenerating code etc.)

Table Data or lists and loop generated data seems complicated at first
sight, but in fact it is not. It should be defined by a table id and
the existing table data should be replaced. More refined you could
replace just data of one column. Why do you need to tell the template
engine "here is a table" with programming language like loop syntax if
there is already the markup information that says "I am a table"? This
is redundant! It is only needed, if your template engine ignores the
markup. The binding of arrays/data to tags does not have to occur in
templates at all.

Simply the idea is not to define magic strings for variable detection,
but use definable tags and replace the content of these tags. This way
<b>every</b> xml data source is your template immediately. Besides
that you will also have templates with meaningful defaults, which are
regenerated only on demand and not on every hit - this will also allow
to make use of the very simple, wellknown and efficient caching
strategy "use static files".

Hope, I was able to transport the basic idea - would be glad if it
echoes some responses.

Thanks for your attention,
have anice day,
Snaky

Monte Ohrt

unread,
Feb 11, 2009, 9:25:13 AM2/11/09
to smarty-d...@googlegroups.com
Just an FYI, Smarty 3 will allow you to create your own template parsers.

Snaky Love

unread,
Feb 11, 2009, 11:45:48 AM2/11/09
to Smarty Developers
hehe, cool, somebody had the same idea - and did the hard work
already! I wanted to use dom and xpath for a first experiment, and
look, what I found:
http://phpquery-library.blogspot.com/2008/12/querytemplates-templating-engine-using.html

Matthias Nothhaft

unread,
Feb 12, 2009, 9:02:09 AM2/12/09
to Smarty Developers
On 11 Feb., 17:45, Snaky Love <snakyl...@googlemail.com> wrote:
> hehe, cool, somebody had the same idea - and did the hard work
> already! I wanted to use dom and xpath for a first experiment, and
> look, what I found:http://phpquery-library.blogspot.com/2008/12/querytemplates-templatin...

I'm not sure if this really helps and for example helps with
decoupling presentation from business logic.

I like the {$foo} syntax as it is not touched by rich text editors. I
use Smarty as a kind of "personalization programming language for web
content authors".

regards,
Matthias

Snor

unread,
Feb 13, 2009, 7:20:33 AM2/13/09
to Smarty Developers
I agree, but I do see the advantages with not having it. It seems like
it's possible to have it worth either way, anyway, so my opinion is to
leave it all how it is.

On Feb 12, 2:02 pm, Matthias Nothhaft

Snor

unread,
Feb 13, 2009, 7:20:33 AM2/13/09
to Smarty Developers
I agree, but I do see the advantages with not having it. It seems like
it's possible to have it worth either way, anyway, so my opinion is to
leave it all how it is.

On Feb 12, 2:02 pm, Matthias Nothhaft
<matthias.nothh...@googlemail.com> wrote:

Snor

unread,
Feb 13, 2009, 7:20:33 AM2/13/09
to Smarty Developers
I agree, but I do see the advantages with not having it. It seems like
it's possible to have it worth either way, anyway, so my opinion is to
leave it all how it is.

On Feb 12, 2:02 pm, Matthias Nothhaft
<matthias.nothh...@googlemail.com> wrote:

Snaky Love

unread,
Feb 19, 2009, 8:11:21 AM2/19/09
to Smarty Developers
is it already possible to do this? I do not see it in svn, how this
could be done?

I really like to have templates which are not looking like templates.
the phpquery thingy seems to be a good way to access xhtml elements
jquery like, but I would like to keep the smarty logiv in my apps.

Gixx

unread,
Feb 23, 2009, 5:45:37 AM2/23/09
to Smarty Developers
Hi,

It's not so clear for first read, but it seems to be a good idea. But
I don't get it how do you handle In-Tag smarty codes like:

<ul id="{if $level eq 1}Menu{else}Submenu{/if}" {if $active eq 1}
class="selected"{/if}>...</ul>

Hm? :)

Yann GAUTHERON

unread,
Feb 23, 2009, 4:20:37 PM2/23/09
to smarty-d...@googlegroups.com
I had the same reflexion...

Gixx a écrit :

Bálint Kriván

unread,
Feb 23, 2009, 4:30:49 PM2/23/09
to smarty-d...@googlegroups.com
With XSLT-style, I think, e.g:

<ul>
<smarty:attribute attr="id"><smarty:if ...>...</smarty:if></smarty:attribute>
<smarty:if ...><smarty:attribute attr="class" value="selected" /></smarty:if>
</ul>

Something like that, but this is just a scratch of course ;)
--
Üdv,
Kriván Bálint

Abalam

unread,
Feb 23, 2009, 4:45:26 PM2/23/09
to Smarty Developers
And you really don't see how it is smart(y)er with the current {}
syntax than you're suggestion ?

I really don't see how it can be useful to write this insane Extreme-
XML-forcefully-demented syntax...

Personally, I'm currently searching to gain time with development, not
the opposite, and you ? How can you gain some time with this form of
template ?
Plus it is very hard to read for a new human resource arriving in the
project...

Bálint Kriván

unread,
Feb 23, 2009, 11:56:31 PM2/23/09
to smarty-d...@googlegroups.com
Well, personally I did not say that it's a "smarty" solution, because it's not. Smarty is a template engine as is.
If someone would like to do magics with tags than he should use XML + XSLT as output generation and not smarty because it just won't do that.
I don't want to be the evil, I just answered the question which was came up :)
--
Üdv,
Kriván Bálint
Reply all
Reply to author
Forward
0 new messages