Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using apply with built-in functions #3139

Closed
wildhaber opened this issue Mar 7, 2017 · 1 comment
Closed

using apply with built-in functions #3139

wildhaber opened this issue Mar 7, 2017 · 1 comment

Comments

@wildhaber
Copy link

wildhaber commented Mar 7, 2017

Introduction

This is a follow up report based on the topic from the discussion board (https://discuss.gohugo.io/t/apply-printf-on-a-sequence/5722) related using built-in functions with apply.

Reproduction information

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)}

Environment information

Version: Hugo Static Site Generator v0.19 windows/amd64
GOOS="windows"
GOARCH="amd64"
GOVERSION="go1.8"
Discussion: https://discuss.gohugo.io/t/apply-printf-on-a-sequence/5722

@bep bep added the Enhancement label Mar 7, 2017
moorereason added a commit to moorereason/hugo that referenced this issue Mar 7, 2017
Add print, printf, and println to the Hugo FuncMap so that they are
accessible to the apply template func.

Updates gohugoio#3139
bep pushed a commit that referenced this issue Mar 8, 2017
Add print, printf, and println to the Hugo FuncMap so that they are
accessible to the apply template func.

Updates #3139
@bep bep closed this as completed Mar 8, 2017
@bep bep added this to the v0.20 milestone Mar 8, 2017
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants