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
2 answers

Why the linker complains about multiple definitions in this template?

This little piece of code triggers the linker's anger when included on at least two translation units (cpp files) : # ifndef MAXIMUM_HPP # define MAXIMUM_HPP template T maximum(const T & a, const T & b) { return a > b ? a : b…
overcoder
  • 1,523
  • 14
  • 24
16
votes
4 answers

Dynamic Template Instantiation

I've got a class template, and I need to declare an object of that class, without defining the type parameters, so that I can define them conditionally later, e.g.: template class A{ public: A(T v){var = v}; ~A(){}; T…
user965369
  • 5,413
  • 13
  • 33
  • 47
16
votes
1 answer

SFINAE tried with bool gives compiler error: "template argument ‘T::value’ involves template parameter"

I tried to implement an SFINAE using bool (unlike popular void_ trick): template struct Resolve { static const bool value = false; }; template struct Resolve { static const…
iammilind
  • 68,093
  • 33
  • 169
  • 336
16
votes
6 answers

Handlebars.js and SEO

I have read a great deal of discussions about javascript templating and Search Engine Optimization. Still, I haven't found a satisfying answer to the question (either poorly-documented or outdated). Currently I am looking into handlebars.js as a…
Maarten
  • 635
  • 2
  • 8
  • 22
16
votes
3 answers

Is making a function template specialization virtual legal?

In C++, a function template specialization is supposed to act exactly like a normal function. Does that mean that I can make one virtual? For example: struct A { template void f(); template <> virtual void f() {} }; struct B…
alexk7
  • 2,721
  • 1
  • 21
  • 18
16
votes
2 answers

How to put a hyperlink in the middle of a paragraph using the slim templating language?

How do you write the following in the slim templating language?

Join the Google group and let us know what you think, or what other features you’d like to see.

I tried the following: p ' Join the a href="" Google Group '…
Erik
  • 4,268
  • 5
  • 33
  • 49
16
votes
2 answers

C++20 Concepts: Constraint Normalization

This is an example from the C++20 Standard (ISO/IEC 14882:2020), Section 13.5.4 ([temp.constr.normal]), Paragraph 1 (emphasis mine): The normal form of a concept-id C is the normal form of the constraint-expression of C, after…
J L
  • 563
  • 3
  • 17
16
votes
1 answer

Passing lambda as an argument to a function with std::function parameter with an arbitrary number of parameters

Consider the next sample of the code: template void foo(std::function f) { } template class Class { public: static void foo(std::function f) { } }; Why can I do…
16
votes
2 answers

Comparing dates in liquid

I'm using Liquid with Jekyll to post dates on my band's website (http://longislandsound.com.au) What I want is to automatically hide old dates, so I don't have to go in and delete them again. I think the best way to do it would be to compare the…
Chris Lawrence
  • 281
  • 1
  • 4
  • 7
16
votes
3 answers

How do you pass an array to an erb template in ruby and have it iterated over?

I need some help with erb templates, I can't seem to get my head around passing an array and then iterating over it. My problem is this. I want to pass a few arrays: ` device => ["eth0", "br0"], ipaddr => ["192.168.12.166",…
matt
  • 805
  • 3
  • 9
  • 14
16
votes
1 answer

Overloaded function templates that differ only in their return types in C++

It is well known that ordinary functions that differ only in their return type cannot be overloaded in C++. But this limitation does not hold for overloaded function templates, for example: int f(auto) { return 1; } auto f(auto) { return 2; } All…
Fedor
  • 17,146
  • 13
  • 40
  • 131
16
votes
4 answers

Encrypting / obfuscating a string literal at compile-time

I want to encrypt/encode a string at compile time so that the original string does not appear in the compiled executable. I've seen several examples but they can't take a string literal as argument. See the following example: template struct…
karliwson
  • 3,365
  • 1
  • 24
  • 46
16
votes
3 answers

Editing Magento sales e-mail payment block

app\locale\en_US\template\email\sales\order_new.html is the file in question. How would one go about editing {{var payment_html}} without affecting other sections of the site? It seems like the section comes from:…
djdy
  • 6,779
  • 6
  • 38
  • 62
16
votes
5 answers

Crazy C++ template - A template to access individual attributes of a class

I am a novice C++ programmer, but I thought I know enough about C++ until today when I came across code like this at work and failed to understand how it actually works. class Object { }; template < class PropObject, class PropType,…
cgcoder
  • 426
  • 4
  • 11
16
votes
4 answers

multi model forms in yii

How to create a multi-model form in Yii? I searched the entire documentation of Yii, but got no interesting results. Can some one give me some direction or thoughts about that? Any help will be appreciable.
NewUser
  • 12,713
  • 39
  • 142
  • 236