jbake icon indicating copy to clipboard operation
jbake copied to clipboard

Access to assets from template

Open McNetic opened this issue 6 years ago • 4 comments

As far as I can see, there is currently not a general way to get access to a list of available assets or check for existence of a specific asset (for example an image) from the templates. I think it is not in the scope of the templating engine to provide such mechanism, as in a webserver environment, models and variables are provided by the web server to the templates, but in a static site generator, it should be the responsibility of the site generator to provide it.

McNetic avatar Mar 20 '18 17:03 McNetic

Would access to a collection of file references (i.e. the assets crawled) be sufficient? As this should be fairly straight forward to expose to the template engines via the data model.

jonbullock avatar Apr 12 '18 12:04 jonbullock

Extending to what @jonbullock said, Should that be a list of every non-content files discovered by the engine? For example, asset collection to use similar to alltags data model that contains list of tag string names. The collection may just contain a relative path of an discovered asset like [/resources/img/abc.png, /resource/css/abc.css]. Templates can then check if path exists in the collection.

manikmagar avatar Apr 12 '18 13:04 manikmagar

Hmm. It should be possible to bind an object to the model. So that we could use something like

meta.getAssets()
meta.findAssetByName('monkey.jpg')
meta.getCurrentTime()
etc.

ancho avatar Apr 13 '18 18:04 ancho

I like the idea of an object API being exposed, saves the end users from re-implementing the same logic over and over in the template engines.

jonbullock avatar Apr 18 '18 12:04 jonbullock