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

Add template func to check if a file exists #3839

Closed
jetwash opened this Issue Aug 26, 2017 · 0 comments

Comments

Projects
None yet
2 participants
@jetwash

jetwash commented Aug 26, 2017

I'd like to be able to do something like

{{ if fileExists (printf "static/%s.jpg" .BaseFileName) }}
  <img src="{{ printf "static/%s.jpg" .BaseFileName }}" />
{{ end }}

For when a file may or may not exist.

FWIW, I'd be okay if imageConfig and/or readFile just returned nil instead of generating errors if the file doesn't exist, but just querying the existence of a file would save resources in my case. In a perfect world, though, fileExists (or whatever you want to call it) would exist and imageConfig/readFile would return nil if the file doesn't exist or can't be read.

@bep bep added the Enhancement label Aug 26, 2017

@bep bep added this to the v0.27 milestone Aug 26, 2017

digitalcraftsman added a commit to digitalcraftsman/hugo that referenced this issue Aug 31, 2017

digitalcraftsman added a commit to digitalcraftsman/hugo that referenced this issue Sep 1, 2017

digitalcraftsman added a commit to digitalcraftsman/hugo that referenced this issue Sep 1, 2017

@bep bep modified the milestones: v0.27, v0.28 Sep 7, 2017

@bep bep modified the milestones: v0.28, v0.29 Sep 21, 2017

@bep bep added the Hacktoberfest label Sep 22, 2017

@bep bep changed the title from Function to check if a file exists to Add template func to check if a file exists Sep 22, 2017

@bep bep modified the milestones: v0.29, v0.30 Sep 26, 2017

@bep bep closed this in #3853 Sep 28, 2017

bep added a commit that referenced this issue Sep 28, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment