Apply printf on a sequence

I’m currently struggling a bit using the apply template function.

Assuming I have a list of numbers 1 to 30 (for example) and I want want to have them all as 5 digit length.

So for a single number I would use:

{{ printf "%05d" 13 }} # 00013

Now I thought about using apply to range through my sequence list and apply this printf like:

{{ apply (seq 30) "printf" "%05d" "." }}
# nope: at <apply (seq 30) "prin...>: error calling apply: can't find function printf
# cannot find function printf?  <- confusing

Next try - combining “printf” and its parameter %05d:

{{ apply (seq 30) (printf "%05d") "." }}
# nope: at <apply (seq 30) (prin...>: error calling apply: can't find function %!d(MISSING)
# ok, so forget about this.

Another try providing the context (.) within the printf method bracket:

{{ apply (seq 30) (printf "%05d" .) }}
# guess what!
# it breaks the page but outputs the right things a million times in the console including a bunch of errors :smiley:
#
# Console: 
# [] [] [] %!d(bool=0true) %!d(bool=false) %!d(string=00000) {63617444825 454000000 00000} {00000 00000 00000} {00702 00800 00004 00000} %!d(string=markdown) %!d(string=00000) %!d(string=article) %!d(bool=0true) %!d(string=00000) [%!d(string=article/single.h
tml) %!d(string=_default/single.html) %!d(string=theme/article/single.html) %!d(string=theme/_default/single.html)] %!d(string=00000) [00043 00043 00043 00013 00010 00100 00097 00116 00101 00032 00061 00032 00034 00050 00048 00049 00054 00045 00049 00050 00045 000
49 00054 00084 00048 00048 00058 00050 00055 00058 00048 00053 00046 00052 00053 00052 00090 00034 00013 00010 00112 00117 00098 00108 00105 00115 00104 00100 00097 00116 00101 00032 00061 00032 00034 00050 00048 00049 00054 00045 00049 00050 00045 00049 00054 000
84 00048 00048 00058 00050 00055 00058 00048 00053 00046 00052 00053 00052 00090 00034 00013 00010 00100 00114 00097 00102 00116 00032 00061 00032 00102 00097 00108 00115 00101 00013 00010 00013 00010 00116 00105 00116 00108 00101 00032 00061 00032 00034 00068 001
01 00098 00117 00103 00103 00105 00110 00103 00032 00105 00110 00032 00072 00117 00103 00111 00032 00109 00097 00100 00101 00032 00101 00097 00115 00121 00034 00013 00010 00116 00097 00103 00115 00032 00061 00032 00091 00034 00100 00101 00098 00117 00103 00103 001
05 00110 00103 00034 00044 00034 00098 00117 00103 00115 00034 00044 00034 00102 00105 00120 00034 00044 00034 00098 00117 00103 00102 00105 00120 00034 00093 00013 00010 00097 00114 00099 00104 00105 00118 00101 00032 00061 00032 00091 00034 00050 00048 00049 000...
# ...had to crop it
#
# then:
# [] 825746248624 map[] {[] [] {%!d(string=error\page-xy.md) %!d(string=page-xy.md) %!d(string=page-xy) <nil> %!d(string=error) %!d(string=error\) %!d(string=000md) %!d(string=64ced4b2ff77fcf39c6717a49203224c) %!d(string=debug-in-hugo) %!d(string
=000en)}} {825749084928 825753536768 00000 00000} 00000 [%!d(string=error)] 825741804800 825741804888 %!d(string=Page Title XY) %!d(string=00000) [] map[%!d(string=Pages):[]] {63617444825 454000000 00000} {63617444825 454000000 00000} {%!d(string=mon
thly) %!d(float64=000.5) %!d(string=sitemap.xml)} %!d(template.HTML=00000) {%!d(string=00000) %!d(string=00000) %!d(string=00000) %!d(string=00000)} 825750408192 %!d(string=/error/page-xy) 00000 825771359872 825744703776 %!d(string=000en)}

This was the end of my tests and even after re-reading the documentation again, I feel lost in this case - and I know I’m doing something wrong ;-).

Any help is very appreciated :slightly_smiling:

Yes. apply looks in the Hugo internal map for existing funcs (printf is a built-in)… which is limiting. But nothing I can do without fixing Hugo. Can you create an issue on GitHub?

Done. Thanks for the reply.