A Little Gotcha in Luminus request in Layout Renders….. #clojure #webdev #luminus

It’s been a while since I looked at the Luminus web development framework for Clojure. I know some folk find it a bit too heavy but I really like it. There have been some changes in releases since I built DeskHoppa so I though I better leave it here incase someone else gets confused by it.

So, the basic page render used to look like this:

(layout/render "mytemplate.html")

Then you could pass in a map for values that would appear in the page.

(layout/render "mytemplate.html" {:key1 value1 :key2 value2})

In more recent releases it now takes the request object.

(layout/render request "mytemplate.html")

Now on first inspection the automatic assumption would be to add key/values to the request.

(assoc request :key3 value3)

Adding to the request will do nothing and have no effect. The render function doesn’t actually do anything with the request when it comes to render the page. You can, however, append parameters to the function after the page name is declared.

(layout/render request "mytemplate.html" {:key1 value1 :key2 value2 :key3 value3})

And the map will get passed to the page so you can use it.

<p>Hi, {{key1}}, you're visiting from {{key2}}!</p>

And so on.

I only mention it because it caught me out for a good half an hour……. thought it might be useful to someone else.

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: