Questions tagged [templates]

Questions on working with templates in Mathematica, File/String/Notebook/Expression Templates and the functions used for manipulations like TemplateApply.

Templating mechanism was largely extended in Version 10. Earlier, templates were only represented by StringForm.

This function still exist but overloaded TemplateApply mimics it:

TemplateApply["Hello, my name is ``. I'm feeling ``.", {"Bob",   "good"}]

is the same as:

StringForm["Hello, my name is ``. I'm feeling ``.", "Bob", "good"]

Till V 9.0 templates are only

35 questions
9
votes
3 answers

Disable templates for user defined functions with usages

It appears that fixing the template system is low on Wolfram Research's priority list. For my package, I have defined Usage info for my functions involving lots of formatting, which causes the template system to run amuck. Since this looks very…
QuantumDot
  • 19,601
  • 7
  • 45
  • 121
5
votes
5 answers

Optional value in StringTemplate

I can use a string template like so: st = StringTemplate["a is `a` and b is `b`"]; st @ <|"a" -> 1, "b" -> 2|> which gives "a is 1 and b is 2" But I would like the parameter b to be optional, so that if I call st @ <|"a" -> 1|> I get simply "a is…
Stephen Powell
  • 1,061
  • 5
  • 13
2
votes
2 answers

How can I pass values to a NamedSlot in TemplateApply

str="``;`v`;`v`;``"; template=StringTemplate@str; TemplateApply[template,CharacterRange["A","Z"]] (*"A;;;D"*) I want to get the result as: (*;A;B;;*) only slot named 'v' is valued as A and B one method is to make 'v' into 'v1' and…
HyperGroups
  • 8,619
  • 1
  • 26
  • 63
1
vote
0 answers

generate a category bar with TemplateApply

Consider we are generating a category bar with 2 levels. This is an example about the XMLTemplate template = XMLTemplate@"
  • :
HyperGroups
  • 8,619
  • 1
  • 26
  • 63