Questions tagged [templates]

The templates tag is used in multiple contexts: generic programming (especially C++), and data/document generation using template engines, web template for a pre-designed webpage, or set of HTML webpages. 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 .

54454 questions
320
votes
6 answers

JSP tricks to make templating easier?

At work I've been tasked with turning a bunch of HTML files into a simple JSP project. It's really all static, no serverside logic to program. I should mention I'm completely new to Java. JSP files seem to make it easy to work with common includes…
Scott
  • 4,070
  • 3
  • 21
  • 16
315
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
  • 98,941
  • 38
  • 226
  • 299
311
votes
10 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
  • 37,207
  • 50
  • 124
  • 185
305
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
  • 22,372
  • 32
  • 121
  • 175
299
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,967
  • 5
  • 29
  • 31
277
votes
12 answers

Can lambda functions be templated?

In C++11, is there a way to template a lambda function? Or is it inherently too specific to be templated? I understand that I can define a classic templated class/functor instead, but the question is more like: does the language allow templating…
Klaim
  • 67,274
  • 36
  • 133
  • 188
272
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
  • 11,550
  • 9
  • 43
  • 63
258
votes
8 answers

How do I edit the Visual Studio templates for new C# class/interface?

I find myself removing the following import statements in nearly every C# file I create in Visual Studio: using System.Collections.Generic; using System.Linq; using System.Text; Of course its really easy to do this with Resharper, but I really…
Jørn Schou-Rode
  • 37,718
  • 15
  • 88
  • 122
254
votes
3 answers

Why do I have to access template base class members through the this pointer?

If the classes below were not templates I could simply have x in the derived class. However, with the code below, I have to use this->x. Why? template class base { protected: int x; }; template class derived : public…
Ali
  • 56,466
  • 29
  • 168
  • 265
250
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: