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
16
votes
4 answers

The kitchen sink of HTML pages

I'm designing web themes and I'd like to put together a "kitchen sink" HTML page which contains the most common design elements of a web page. It's great to show theme features but also helps me develop CSS for everything on the page without missing…
Tak
  • 11,428
  • 5
  • 29
  • 48
16
votes
2 answers

django templates - using block.super in included template fails (exception)

the idea is to to have multiple widgets on a page and include all js and css files needed form this 'widgets' (it's easy to manage files this way). Duplicated files is not a problem. Every widget's template is included into a page by…
robertzp
  • 1,415
  • 1
  • 13
  • 10
16
votes
1 answer

how do I include quoted HTML in a Tornado Template?

I'm using Tornado Templates and one of my fields is a string that has HTML tags quoted in it, e.g.

Solar power

When I render it into the template, the tags are quoted verbatim instead of treated as tags. {{ quoted_html }} So it looks…
Brad
  • 735
  • 1
  • 8
  • 15
16
votes
1 answer

Floating-point types as template parameter in C++20

According to cppreference C++20 now supports floating-point parameters in templates. I am, however, unable to find any compiler support information on that site as well as on others. Current gcc trunk just does it, the others are negative. I would…
non-user38741
  • 671
  • 5
  • 19
16
votes
5 answers

How to specialize Iterator by its value type, in C++?

Is it possible to specialize an Iterator template parameter by its value_type? I have a function with the following prototype. template void f(InputIterator first, InputIterator last); And I want to handle specially if…
niboshi
  • 1,448
  • 3
  • 12
  • 20
16
votes
2 answers

How to pass a reference to a template typename argument

Is there a way to pass a reference as an argument to a template typename argument? I mean so instead of passing an int, for example, to pass a reference to an int. template struct Foo { Foo(T arg) : ptr(arg) {} T ptr; }; int…
Zebrafish
  • 11,682
  • 3
  • 43
  • 119
16
votes
3 answers

Variadic templates: unfold arguments in groups

I have a function that takes two arguments: template void foo(T1 arg1, T2 arg2) { std::cout << arg1 << " + " << arg2 << '\n'; } And a variadic one that should forward its arguments in pairs : template
Fourmet
  • 538
  • 2
  • 12
16
votes
2 answers

Why is the Visual Studio C++ Compiler rejecting an enum as a template parameter?

I'm using the Microsoft Visual Studio 2019 compiler (cl.exe), and it is rejecting some code accepted by both Clang and GCC, related to using enums as template parameters, where the templates are specialized for particular enum values. enum Foo { …
16
votes
6 answers

Member function templates cannot be declared virtual - From Addison Wesley: C++ Templates

From Addison Wesley: C++ Templates Member function templates cannot be declared virtual. This constraint is imposed because the usual implementation of the virtual function call mechanism uses a fixed-size table with one entry per virtual…
Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
16
votes
4 answers

How to retrieve variadic template parameters without auxillary function template?

Suppose I have template struct Ints { }; class MyClass { public: Ints<1, 2, 3> get() { return Ints<1, 2, 3>(); } }; What I want to do is simple. template vector MyFunc1(T& x) { Ints result = x.get(); …
i.stav
  • 444
  • 3
  • 9
16
votes
2 answers

Why is implicit conversion not ambiguous for non-primitive types?

Given a simple class template with multiple implicit conversion functions (non-explicit constructor and conversion operator), as in the following example: template class Foo { private: T m_value; public: Foo(); Foo(const T&…
Cybran
  • 2,203
  • 2
  • 17
  • 34
16
votes
1 answer

SFINAE template specialization precedence

#include #include #include template struct trait; template struct trait().begin(), std::declval().end(), void() )> { …
SU3
  • 5,064
  • 3
  • 35
  • 66
16
votes
4 answers

Can I extend variant in C++?

I'm not sure that this is possible, but say I have: using my_variant = std::variant; Now at some point, I create a Class4 and would like to extend my_variant2 to include all of my_variant along with Class4 (in a general way,…
Sebastian
  • 715
  • 6
  • 13
16
votes
2 answers

Looking up data by key in Hugo with a string

I'm trying to create a HUGO-based API documentation site which reads JSON schemas, and prints them in HTML. I'm almost there, but I'm stumped on how exactly to pass in the data I want to a partial. Given a standard JSON schema file, such as the…
Garrett Amini
  • 423
  • 3
  • 10
16
votes
6 answers

Django extract string from [ErrorDetail(string='Test Message', code='invalid')]

I would like to show in my template only message that is in string variable, but I don't know how. I am using Django Rest Framework. My code: form.html

{{ serializer.amount.errors }}

serializers.py from rest_framework import serializers from…
mpj
  • 327
  • 1
  • 2
  • 12