Search code examples
clojureluminus

clojure luminus global variable access into template


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


Solution

  • 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.