Questions tagged [template-variables]

Template variables consist of any of various conventions for declaring, initializing, composing or evaluating variables and expressions within a template engine.

Overview

Template variables consist of any of various conventions for declaring, initializing, composing or evaluating variables and expressions with a

See also

55 questions
93
votes
4 answers

Use placeholders in YAML

Is there a way to use placeholders in YAML like this: foo: &FOO <>: type: number default: <> bar: - *FOO propname: "some_prop" default: "some default"
55
votes
8 answers

Does PHP have a feature like Python's template strings?

Python has a feature called template strings. >>> from string import Template >>> s = Template('$who likes $what') >>> s.substitute(who='tim', what='kung pao') 'tim likes kung pao' I know that PHP allows you to write: "Hello $person" and have…
Casebash
  • 114,675
  • 90
  • 247
  • 350
53
votes
6 answers

How to get list of all variables in jinja 2 templates

I am trying to get list of all variables and blocks in a template. I don't want to create my own parser to find variables. I tried using following snippet. from jinja2 import Environment, PackageLoader env = Environment(loader=PackageLoader('gummi',…
Kracekumar
  • 19,457
  • 10
  • 47
  • 56
29
votes
4 answers

string.format() with optional placeholders

I have the following Python code (I'm using Python 2.7.X): my_csv = '{first},{middle},{last}' print( my_csv.format( first='John', last='Doe' ) ) I get a KeyError exception because 'middle' is not specified (this is expected). However, I want all of…
void.pointer
  • 24,859
  • 31
  • 132
  • 243
25
votes
5 answers

String interpolation in YAML

In Perl I can do something like the following: my $home = "/home"; my $alice = "$home/alice"; Can I do something like the following in YAML: Home: /home Alice: $Home/alice So "Alice" is effectively /home/alice in the end?
Clinton
  • 22,361
  • 15
  • 67
  • 163
11
votes
1 answer

Linker error with variable templates

Consider the code below: #include template T n; int main() { n = 42; std::cout << n << std::endl; } It compiles and links with g++5.1, and it displays 42. However, clang++ fails to link it: undefined…
vsoftco
  • 55,410
  • 12
  • 139
  • 252
7
votes
2 answers

Python template safe substitution with the custom double-braces format

I am trying to substitute variables in the format {{var}} with Python's Template. from string import Template class CustomTemplate(Template): delimiter = '{{' pattern = r''' \{\{(?: (?P\{\{)| …
reggie
  • 3,523
  • 14
  • 62
  • 97
6
votes
1 answer

Can I overload template variables?

I want to declare something like this: template constexpr enable_if_t, int[]> foo = { 1, 2 }; template constexpr enable_if_t, int[]> foo = { 10, 20, 30 }; But when I try to I'm…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
6
votes
1 answer

g++ and clang++ different behaviour with variable template and SFINAE

Another question of type "who's right between g++ and clang++?" for C++ standard gurus. Suppose we want apply SFINAE to a variable template to enable the variable only if the template type fulfill a certain condition. By example: enable bar if (and…
max66
  • 65,235
  • 10
  • 71
  • 111
6
votes
1 answer

member template variable specializing

A class can contain a member template variable which must be static: class B { public: template static X var; B() { std::cout << "Create B " << __PRETTY_FUNCTION__ << std::endl; } template…
Klaus
  • 24,205
  • 7
  • 58
  • 113
5
votes
3 answers

Why Must Specializing Argument be void?

So yet another question in this saga. Guillaume Racicot has been good enough to provide me with yet another workaround so this is the code I'll be basing this question off of: struct vec { double x; double y; double z; }; namespace…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
5
votes
2 answers

Working Around a Visual Studio Internal Compiler Error With Nested Templated Variables

I'm trying to write code that will let me index into the parameter types of a function: template R function_return(R(*)(ARGS...)); template std::tuple
5
votes
1 answer

Should template variable C-array full specialization specify array size?

I am trying to implement a templated C-array with specialization as the following: // template definition template< int a, int b > constexpr int arr[] = { 1 }; // partial specialization, works ok template< int b > constexpr double…
4
votes
0 answers

Grafana chained variables in repeating rows

I have a dashboard that uses two variables: $clients is a static list and $running_sessions is the result of a MySql query that uses $clients (something like select id from sessions where client_id in ($clients)). I have a row that repeats per…
3
votes
1 answer

Templated Function Pointer Arrays in Visual Studio

Guillaume Racicot gave an excellent answer to this question on how I could specialize template variables. But I'm having trouble in visual-studio-2017 with creating a templated array of function pointers. This code for example: struct vec { …
1
2 3 4