##// END OF EJS Templates
help: add documentation for new template functions
Sean Farley -
r18465:3aa8b4b3 stable
parent child Browse files
Show More
@@ -38,3 +38,61 b' You can also use a chain of filters to g'
38 List of filters:
38 List of filters:
39
39
40 .. filtersmarker
40 .. filtersmarker
41
42 Note that a filter is nothing more than a function call, i.e.
43 ``expr|filter`` is equivalent to ``filter(expr)``.
44
45 In addition to filters, there are some basic built-in functions:
46
47 - if(expr, then[, else])
48
49 - ifeq(expr, expr, then[, else])
50
51 - sub(pat, repl, expr)
52
53 - join(list, sep)
54
55 - label(label, expr)
56
57 - date(date[, fmt])
58
59 - fill(text[, width])
60
61 Also, for any expression that returns a list, there is a list operator:
62
63 - expr % "{template}"
64
65 Some sample command line templates:
66
67 - Format lists, e.g. files::
68
69 $ hg log -r 0 --template "files:\n{files % ' {file}\n'}"
70
71 - Join the list of files with a ", "::
72
73 $ hg log -r 0 --template "files: {join(files, ', ')}\n"
74
75 - Format date::
76
77 $ hg log -r 0 --template "{date(date, '%Y')}\n"
78
79 - Output the description set to a fill-width of 30::
80
81 $ hg log -r 0 --template "{fill(desc, '30')}"
82
83 - Use a conditional to test for the default branch::
84
85 $ hg log -r 0 --template "{ifeq(branch, 'default', 'on the main branch',
86 'on branch {branch}')}\n"
87
88 - Append a newline if not empty::
89
90 $ hg tip --template "{if(author, '{author}\n')}"
91
92 - Label the output for use with the color extension::
93
94 $ hg log -r 0 --template "{label('changeset.{phase}', node|short)}\n"
95
96 - Invert the firstline filter, i.e. everything but the first line::
97
98 $ hg log -r 0 --template "{sub(r'^.*\n?\n?', '', desc)}\n"
General Comments 0
You need to be logged in to leave comments. Login now