0

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)

Dan Jay
  • 874
  • 10
  • 27

2 Answers2

3

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}}
Marty Gentillon
  • 127
  • 1
  • 3
-1

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

{% include right-page %}

Taha Husain
  • 292
  • 2
  • 11
  • 2
    This doesn't work. Selmer works on pre-caching the full page. A runtime value for the template name will *not* work. The other answer by @Marty Gentillon is correct – kopos Sep 08 '18 at 07:00