Questions tagged [templates]

The templates tag is used in multiple contexts: generic programming (especially C++), and data/document generation using template engines. When using this tag on implementation heavy questions - tag the code language the implementation is written in.

The templates tag is used in multiple contexts:

C++ templates

Templates in allow for generic programming and . The C++ Book Guide contains books treating templates as well, especially:

Before asking a question, consider looking into these FAQs first:

There are also useful questions on StackOverflow:

Books

Other templates (PHP, django, drupal, mediawiki, etc.)

There are several varieties of template engines used with web servers, web applications, and web scripting languages. Questions for these types of templates should use the language specific tag.

The web server or scripting language templates are different from templates as used in or generics as used in . These templates are used to help with separating view or presentation of data with the business logic generating or transforming the data.

PHP template questions should use the specific template product tag such as , , etc.

django template questions should use .

drupal template questions should use .

mediawiki template questions should use .

49783 questions
281
votes
3 answers

Set variable in jinja

I would like to know how can I set a variable with another variable in jinja. I will explain, I have got a submenu and I would like show which link is active. I tried this: {% set active_link = {{recordtype}} -%} where recordtype is a variable…
MyTux
  • 2,819
  • 2
  • 13
  • 4
277
votes
5 answers

How do I accomplish an if/else in mustache.js?

It seems rather odd that I can't figure how to do this in mustache. Is it supported? This is my sad attempt at trying: {{#author}} {{#avatar}} {{/avatar}} {{#!avatar}}
egervari
  • 21,108
  • 30
  • 115
  • 171
267
votes
10 answers

What are some uses of template template parameters?

I've seen some examples of C++ using template template parameters (that is templates which take templates as parameters) to do policy-based class design. What other uses does this technique have?
Ferruccio
  • 93,779
  • 37
  • 217
  • 294
265
votes
11 answers

How to use Class in Java?

There's a good discussion of Generics and what they really do behind the scenes over at this question, so we all know that Vector is a vector of integer arrays, and HashTable is a table of whose keys are strings and values…
Karl
  • 8,158
  • 5
  • 27
  • 29
262
votes
8 answers

Django template how to look up a dictionary value with a variable

mydict = {"key1":"value1", "key2":"value2"} The regular way to lookup a dictionary value in a Django template is {{ mydict.key1 }}, {{ mydict.key2 }}. What if the key is a loop variable? ie: {% for item in list %} # where item has an attribute…
Stan
  • 32,761
  • 45
  • 112
  • 170
247
votes
7 answers

Function passed as template argument

I'm looking for the rules involving passing C++ templates functions as arguments. This is supported by C++ as shown by an example here: #include void add1(int &v) { v+=1; } void add2(int &v) { v+=2; } template
SPWorley
  • 10,852
  • 9
  • 41
  • 61
243
votes
8 answers

How to use if statements in underscore.js templates?

I'm using the underscore.js templating function and have done a template like this: