0
votes

I'm trying to do a simple thing(at least for common frameworks) using Luminus and Selmer template but I can’t find a way to do it. I would like just to pass values to the base template, something like this:

file: home.html

{% extends "base.html" {:user {{ user }} } %}
​{% block content %}
...
​{% endblock %}

I know that we can do it using render a file, like this

(render-file "html/base.html" {:user user})

But it not looks right, it looks like a weird workaround.

My idea actually is to make some global variables to access anywhere of application like user session, but I didn’t find it in luminus documentation

1
Pardons if you're locked into the text-template solution, but, if not: there are better-trodden paths in Clojure. Data literals for element structures, so output encoding/escaping can be automatic. Snippets can be pure functions that compose with ordinary program logic. Immutable data lets you partly process a template and use the result as the starting point for many independent final customizations. Meanwhile, you avoid text templates' weak points: yet another notation, with severe limits; repetition of effects in program code when you pass that limit, & double encoding. - Biped Phill

1 Answers

1
votes

Well, even when Selmer is cool, most of the web culture in Clojure turns around Hiccup as the template generator. You will use Hiccup with ClojureScript (Reagent - Re-frame) and that is another reason to switch to it. Probably you already have Hiccup installed, check it with:

lein deps :tree | grep hiccup  

You will need to create a layout like this one. And uses it in a "controller" like this to build your HTML view.