Framework for client- and server-side templating

Hi!

There’re so many template engines for both frontend and backend. But they all lack of incorporating with each other. Templates written for backend rendering cannot be reused for frontend and vise versa.

For instance, how can i implement a template written in Smarty on the client-side? Those templates all depend on a specific engine and are therefore not reusable.

Why are they all so popular? (Twig, Smarty, Plates, Jade, Haml, Mustache, Handlebars, Dust, Ctemplate, etc, etc, etc)

Here is a simple example. Let’s assume this template which will be evaluated server-side:

<div>Hello {{name}}</div>

After rendering i get something like this: <div>Hello Bill</div>

Now there’s is no way i can reference back to ‘name’ in the frontend.

Why don’t we simply write templates using nothing but html. Maybe like so?

<div>Hello <span></span></div>

Are there already template engines like this for frontend and backend, which simply allows to bind or link data to an element or attribute.

The closest i could find which does about what i have in mind is pure.js It was already written back in 2008 (although there’re some points i don’t ike about it). But for server-side?

Here are my criteria for such a template engine:

  • No inline logic. Separation between representation and logic
  • Templates must be written in pure html (no embedded complex language such as Mustache) and can be implemented in frontend and backend.
  • (optional) Collaboration between frontend and backend by both following the same api.

Please let me know what you think, many thanks!

By definition it would be impossible to do that because HTML doesn’t contain the tags – the language construct. However, if you simply mean tag like syntax you could just use XSLT since XSLT contains many of the constructs necessary to perform presentation based logic.

I would however question the problem this solves if it is for anything other than an exercise.

You might also be interested in looking into Meteor since I think it offers nearly what you’re asking for.

Additionally exposing ALL server-side data to the client opens a huge security hole.

I am also contemplating this concept and ran into this the other day.

Nicholas Mertens has already come up with a starting library for PHP. We just need the JS equivalent and we are off and running. :wink:

Oh, and the premise of “use HTML not some extra language in your templates” is what Angular and Aurelia go by. I’d say that is one of their winning concepts.

Scott

1 Like

Thanks for you reply!

I’ve already looked into XSLT and TAL. There are however a few issues i see here.

Validations, ending up writing logic in your templates and that you need to offer your data in a xml format.

Meteor looks great and i think this is where the future of web development will and really should be heading to, to be able to write your application in one single language, for both frontend and backend tasks and in the same manner.
My current situation however doesn’t allow me to install additional platforms on the server (Apache). I’m really thinking about switching though… yea, i really should.

Additionally exposing ALL server-side data to the client opens a huge security hole.

There would be a security hole which would require additional functionality to restrict what tasks and data may be exposed to the client.

I actually forgot yo mention two small libraries i found for backend:

This is the direction i’m proposing.

Hey! tempan looks really promising, the pdf is really fun to read and pretty much describes my generel concerns. I will take a closer look.

Yes, I like the concept too, but I personally don’t want the whole web only revolving around Javascript. Yikes! :open_mouth:

Scott

Yep, Yikes. Sadly thats the trend right now, frontend developers taking over backend jobs.

However, after all i think that’s the right direction for the evolution of the web, where the line between frontend and backend gets more blurred.

What we need is a totally new environment and platform, with no frontend or backend.
Probably a totaly new language is needed. Maybe something like Dart, but natively supported.

What about separation of concerns.

Although I mentioned meteor I would caution usage on projects because it is so new and unproven. The last thing you want is to sink resources into something that is obsoleted and/or never really makes it off the ground. From a business standpoint it makes more sense to use php, ruby, .net, python, node or java. While each language has it faults the amount of resources available alone make the after-mentioned languages more viable than Meteor at the current time.

That statement of mine was indeed a little far-fetched ; )

But if we look at the vast amount of frameworks, libraries and platforms popping out everyday, then there is obviously the need for a different achritecture of how we build web-apps, they’re no longer web-sites.

I would partially disagree. All the top languages are more than adequate for achieving just about anything. You just have to know how to use them. Not to mention they are all evolving to make them even more adequate with todays needs.

Though the grass is always greener on the other side…

Well, i totaly agree.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.