How to add a dynamically concatenated file name for "include" tag in Selmer (Clojure)?

250 views Asked by At

I'm new to Clojure. My issue is regarding selmer templating library.

What I want to do is apply a variable for following way. But its not working;

{% include  {{right-page}} %} -------  X

(here right-page is a concatenated sting for a target file name)

2

There are 2 answers

1
Taha Husain On BEST ANSWER

If right-page is a valid string you're passing to the page, I think this will work for you

{% include right-page %}

0
Marty Gentillon On

Any targets for including in selmer must currently be known when selmer compiles the template, which it does without the passed in data. This means that, given the template:

template.html_template:

{% include right-page %}

and the clojure code:

(selmer/render-file template.html_template 
                    {right-page "some/other/template/file.html_template})

You can expect an exception. As for a work around, you might consider

(selmer/render-file template.html_template 
  {right-page (selmer/render-file 
                "some/other/template/file.html_template {})})

or something similar.

You will, of course have to update template.html to include the already rendered text, and to disable escaping, like so:

template.html_template:

{{right-page|safe}}