You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a recent PR, it was suggested to add built-in support for Mustache.jl and OteraEngine.jl templating. I liked the idea and wanted to see what kind of interface I could come up with. Below I go more into how they're used, but I want to know if people think this belongs in this package. This package was marketed as a "light-weight" alternative and I'd like to hear the community feedback on whether this belongs in the project or not.
They return a helper function to render the loaded template with data. Returning a render function optionally allows us to load templates only once to reduce overhead
They automatically determine the mime type of the templated content ( can template different types of files html, xml, etx...)
What would this look like in practice?
using Oxygen
# define our template
mustache_template_str =""" Hello {{name}} You have just won {{value}} dollars!"""# load the template and provide a helper function to create the HTML Response# (the name of this variable doesn't matter)
render =mustache(mustache_template_str)
# render this template with our data and return an HTML.Response @get"/mustache/string"function()
data =Dict("name"=>"Chris", "value"=>10000)
returnrender(data)
end
Here's how you could load a template from a file:
using Oxygen
# load the template once (assume this is similar to the template defined above)
render =mustache("./congratulations.html")
# render the loaded template with dynamic data@get"/mustache/file/{name}/{value}"function(req, name::String, value::Float64)
data =Dict("name"=> name, "value"=> value)
returnrender(data)
end
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In a recent PR, it was suggested to add built-in support for Mustache.jl and OteraEngine.jl templating. I liked the idea and wanted to see what kind of interface I could come up with. Below I go more into how they're used, but I want to know if people think this belongs in this package. This package was marketed as a "light-weight" alternative and I'd like to hear the community feedback on whether this belongs in the project or not.
What do these templating helpers do?
What would this look like in practice?
Here's how you could load a template from a file:
For those who want to checkout the implementation, here's the source code for these proposed changes:
https://github.com/ndortega/Oxygen.jl/blob/feature/templating-support/src/templating.jl#L33
3 votes ·
Beta Was this translation helpful? Give feedback.
All reactions