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
208
votes
14 answers

C++ templates that accept only certain types

In Java you can define generic class that accept only types that extends class of your choice, eg: public class ObservableList { ... } This is done using "extends" keyword. Is there some simple equivalent to this keyword in C++?
mgamer
  • 13,580
  • 25
  • 87
  • 145
205
votes
3 answers

"Undefined reference to" template class constructor

I have no idea why this is happenning, since I think I have everything properly declared and defined. I have the following program, designed with templates. It's a simple implementation of a queue, with the member functions "add", "substract" and…
Heathcliff
  • 3,048
  • 4
  • 25
  • 44
204
votes
18 answers

jQuery templating engines

I am looking for a template engine to use client side. I have been trying a few like jsRepeater and jQuery Templates. While they seem to work OK in FireFox they all seem to break down in IE7 when it comes down to rendering HTML tables. I also took a…
Maurice
  • 27,582
  • 5
  • 49
  • 62
203
votes
13 answers

What are the differences between Generics in C# and Java... and Templates in C++?

I mostly use Java and generics are relatively new. I keep reading that Java made the wrong decision or that .NET has better implementations etc. etc. So, what are the main differences between C++, C#, Java in generics? Pros/cons of each?
pek
  • 17,847
  • 28
  • 86
  • 99
203
votes
5 answers

How to check if a variable exists in a FreeMarker template?

I have a Freemarker template which contains a bunch of placeholders for which values are supplied when the template is processed. I want to conditionally include part of the template if the userName variable is supplied, something like: [#if_exists…
Dónal
  • 185,044
  • 174
  • 569
  • 824
197
votes
5 answers

Default template arguments for function templates

Why are default template arguments only allowed on class templates? Why can't we define a default type in a member function template? For example: struct mycclass { template void mymember(T* vec) { // ... } }; Instead, C++…
Arman
  • 4,566
  • 10
  • 45
  • 66
196
votes
13 answers

*ngIf else if in template

How would I have multiple cases in an *ngIf statement? I'm used to Vue or Angular 1 with having an if, else if, and else, but it seems like Angular 4 only has a true (if) and false (else) condition. According to the documentation, I can only…
user358089
194
votes
6 answers

Angularjs Template Default Value if Binding Null / Undefined (With Filter)

I have a template binding that displays a model attribute called 'date' which is a date, using Angular's date filter. {{gallery.date | date:'mediumDate'}} So far so good. However at the moment, if there is no value…
Undistraction
  • 42,754
  • 56
  • 195
  • 331
191
votes
8 answers

std::enable_if to conditionally compile a member function

I am trying to get a simple example to work to understand how to use std::enable_if. After I read this answer, I thought it shouldn't be too hard to come up with a simple example. I want to use std::enable_if to choose between two member-functions…
evnu
  • 6,450
  • 2
  • 27
  • 38
190
votes
3 answers

Static member initialization in a class template

I'd like to do this: template struct S { ... static double something_relevant = 1.5; }; but I can't since something_relevant is not of integral type. It doesn't depend on T, but existing code depends on it being a static member…
Alexandre C.
  • 55,948
  • 11
  • 128
  • 197
186
votes
14 answers

How to Debug Variables in Smarty like in PHP var_dump()

I have some variables inside a template and I don't know where I assigned them. I need to know what is inside a particular variable; for instance, say I have a variable in smarty called member. I tried with {debug} but it didn't work, and no popup…
streetparade
  • 32,000
  • 37
  • 101
  • 123
185
votes
4 answers

How to create a template function within a class? (C++)

I know it's possible to make a template function: template void DoSomeThing(T x){} and it's possible to make a template class: template class Object { public: int x; }; but is it possible to make a class not within a…
user98188
184
votes
24 answers

Bash Templating: How to build configuration files from templates with Bash?

I'm writing a script to automate creating configuration files for Apache and PHP for my own webserver. I don't want to use any GUIs like CPanel or ISPConfig. I have some templates of Apache and PHP configuration files. Bash script needs to read…
Vladislav Rastrusny
  • 29,378
  • 23
  • 95
  • 156
182
votes
13 answers

Application not picking up .css file (flask/python)

I am rendering a template, that I am attempting to style with an external style sheet. File structure is as follows. /app - app_runner.py /services - app.py /templates - mainpage.html /styles -…
Zack
  • 13,454
  • 24
  • 75
  • 113
181
votes
8 answers

std::function vs template

Thanks to C++11 we received the std::function family of functor wrappers. Unfortunately, I keep hearing only bad things about these new additions. The most popular is that they are horribly slow. I tested it and they truly suck in comparison with…
Red XIII
  • 5,771
  • 4
  • 28
  • 29