SkippyFlipjack
SkippyFlipjack

Reputation: 522

Passing form action into a Jade template

I have a Jade template with an HTML form on it. The action of the form is conditional and depends on information outside the Jade template, so I want to pass it in. How do I do that? Code snippet:

ExpressJS app:

    router.get('/report', function(req, resp) {
      resp.render('report_template', { 
        'formAction': 'http://reporting.server.com/report1/' 
        });
    });

Jade template:

form(id="report", name="report", action=formAction, method="post")

Upvotes: 0

Views: 2587

Answers (2)

amir Mohseninia
amir Mohseninia

Reputation: 1

Caution Previous versions of Pug/Jade supported an interpolation syntax such as:

a(href="/#{url}") Link This syntax is no longer supported. Alternatives are found below. (Check our migration guide for more information on other incompatibilities between Pug v2 and previous versions.)

https://pugjs.org/language/attributes.html#attribute-interpolation

Upvotes: 0

Raphael Serota
Raphael Serota

Reputation: 2197

form(id="report", name="report", action="#{formAction}", method="post")

You need to use #{} to access variables in jade templates.

Upvotes: 1

Related Questions