Questions tagged [template-engine]

A template engine is software that is designed to process templates and content information to produce output documents.

A template engine is software that is designed to process templates and content information to produce output documents, for example:


Paul Sweatte, in an answer to a now-deleted question, provided the following resources on the evolution of separating content from presentation and insights on the historical evolution of template engines:

The W3 Word Processor Filters page is essential reading that should cover most of the basics. For more details, here some resources on the evolution of separating content from presentation:

Markup and typesetting languages are the earliest examples of templating.
Here is the Wikipedia definition:

A markup language is a modern system for annotating a document in a way that is syntactically distinguishable from the text. The idea and terminology evolved from the "marking up" of manuscripts, i.e., the revision instructions by editors, traditionally written with a blue pencil on authors' manuscripts. Examples are typesetting instructions such as those found in troff and LaTeX, or structural markers such as XML tags.

Here is a diagram:

                RUNOFF                      "Generic Coding"                 "Editorial Structure Tags"
           (Jerome Saltzer, 1964)         (William Tunnicliffe, 1967)          (Stanley Rice, pre-1970)
                    |                               |                                     |
                    |                               |                                     |
TeX          roff - nroff - troff                   |-------------------------------------|  (Don Knuth, 1977)   (Josef Osanna, 1973)                   |
                                                   GML
                                            (Charles Goldfarb, 1969)
                                                    |                       SCRIBE
                                                    |                   (Brian Reid, 1980)
                                                    |                          |
                                                    |--------------------------|
                                                  SGML
                                              (Standard, 1980)
                                             |                |
                                             |                |
                                           HTML              XML
                                    (Berners-Lee, 1990)    (Standard, 1998)

As far as web site templating, SSI is the mother of them all.

1649 questions
272
votes
21 answers

Is there a template engine for Node.js?

I'm experimenting with building an entire web application using Node.js. Is there a template engine similar to (for example) the Django template engine or the like that at least allows you to extend base templates?
Seb
  • 3,059
  • 3
  • 18
  • 6
270
votes
8 answers

How to use underscore.js as a template engine?

I'm trying to learn about new usages of javascript as a serverside language and as a functional language. Few days ago I heard about node.js and express framework. Then I saw about underscore.js as a set of utility functions. I saw this question on…
223
votes
3 answers

React.js: Wrapping one component into another

Many template languages have "slots" or "yield" statements, that allow to do some sort of inversion of control to wrap one template inside of another. Angular has "transclude" option. Ruby/Rails has yield statement. If React.js had yield statement,…
NVI
  • 14,907
  • 16
  • 65
  • 104
209
votes
10 answers

how to reference a YAML "setting" from elsewhere in the same YAML file?

I have the following YAML: paths: patha: /path/to/root/a pathb: /path/to/root/b pathc: /path/to/root/c How can I "normalise" this, by removing /path/to/root/ from the three paths, and have it as its own setting, something like: paths: root:…
Andrew Bullock
  • 36,616
  • 34
  • 155
  • 231
121
votes
15 answers

Truncate string in Laravel blade templates

Is there a truncate modifier for the blade templates in Laravel, pretty much like Smarty? I know I could just write out the actual php in the template but i'm looking for something a little nicer to write (let's not get into the whole PHP is a…
fl3x7
  • 3,723
  • 6
  • 26
  • 37
109
votes
15 answers

How do I use Django templates without the rest of Django?

I want to use the Django template engine in my (Python) code, but I'm not building a Django-based web site. How do I use it without having a settings.py file (and others) and having to set the DJANGO_SETTINGS_MODULE environment variable? If I run…
Daryl Spitzer
  • 143,156
  • 76
  • 154
  • 173
94
votes
2 answers

Get loop index of outer loop

In jinja, the variable loop.index holds the iteration number of the current running loop. When I have nested loops, how can I get in the inner loop the current iteration of an outer loop?
flybywire
  • 261,858
  • 191
  • 397
  • 503
86
votes
8 answers

How to create global variables accessible in all views using Express / Node.JS?

Ok, so I have built a blog using Jekyll and you can define variables in a file _config.yml which are accessible in all of the templates/layouts. I am currently using Node.JS / Express with EJS templates and ejs-locals (for partials/layouts. I am…
Cory Gross
  • 36,833
  • 17
  • 68
  • 80
79
votes
5 answers

What Javascript Template Engines you recommend?

I would like to know your opinion about javascript template engine, which one you think is better in terms of performance? I found some links where people do…
kaha
  • 1,417
  • 2
  • 17
  • 21
76
votes
5 answers

Velocity vs. FreeMarker

Velocity or FreeMarker? They look pretty much the same, even the syntax? What to use? Or when to use what?
flybywire
  • 261,858
  • 191
  • 397
  • 503
74
votes
7 answers

C# template engine

I am looking for a stand-alone, easy to use from C# code, template engine. I want to create an HTML and XML files with placeholders for data, and fill them with data from my code. The engine needs to support loops (duplicating parts of the template…
me
70
votes
7 answers

Render an ERB template with values from a hash

I must be overlooking something very simple here but I can't seem to figure out how to render a simple ERB template with values from a hash-map. I am relatively new to ruby, coming from python. I have an ERB template (not HTML), which I need…
sharat87
  • 7,330
  • 12
  • 55
  • 80
70
votes
3 answers

Declare CSS style outside the "HEAD" element of an "HTML" page?

my use-case is the following : I'm composing an HTML page by using parts that are valid HTML fragments but not valid pages, like Divs; these elements are using CSS to manage their style. I'd like to allow each fragment to be responsible for its own…
Pragmateek
  • 13,174
  • 9
  • 74
  • 108
69
votes
16 answers

How to retrieve all Variables from a Twig Template?

Is it possible to retrieve all variables inside a Twig template with PHP? Example someTemplate.twig.php: Hello {{ name }}, your new email is {{ email }} Now I want to do something like this: $template =…
Stefan Neubig
  • 958
  • 1
  • 7
  • 8
64
votes
13 answers

C++ HTML template framework, templatizing library, HTML generator library

I am looking for template/generator libraries for C++ that are similar to eg. Ruby's Erb, Haml, PHP's Smarty, etc. It would be great if I it would sport some basic features like loops, if/else, int conversion to strings, etc. Parameter passing to…
Marcin Gil
  • 68,043
  • 8
  • 59
  • 60
1
2 3
99 100