I want to access the current page URL in my Selmer templates so that I can pass it to an edit page action so that this page can include a link back to the 'calling' page even after editing.
Here's the template code in my Selmer template -- this seems OK:
<a href="/photos/_edit/{{p.path}}{% if back %}?back={{back}}{% endif %}"
class="btn btn-warning btn-sm">edit</a>
Here's how I set the back value when searching:
(defn photo-search [word req]
(layout/render
"search.html"
{:word word
:photos (db/photos-with-keyword-starting word)
:back (str (:uri req) "?" (:query-string req))
}))
;; ...
(defroutes home-routes
;; ...
(GET "/photos/_search" [word :as req] (photo-search word req))
This works OK. However I have other methods that return lists of photos, and it seems to violate the DRY principle to add this code to all other methods.
Is there an easier way to do this, maybe with some middleware?