Inside the pug file, the variables must go with a script in front, in such a way that:
- var url = window.location;
- var urlcomplete = url.href;
- var urlparts = urlcomplete.split("/");
- var years = urlparts[urlparts.length - 1];
- var route = "/app/imagenes/"+years; //variable a pasar
form(action=route method="POST" enctype="multipart/form-data")
You have the example: link
Edited
In this case, location.href will not find it. To change the href of the formula you have to resort to create a javascript code.
In jade, to generate a script the label script.
is used (note the end point), in this way what is tabulated inside will be javascript code.
We can use this to create the formula and then set the action by means of javascript:
form(id="formr" method="POST" enctype="multipart/form-data")
script.
var url = window.location;
var urlcomplete = url.href;
var urlparts = urlcomplete.split("/");
var years = urlparts[urlparts.length - 1];
var route = "/app/imagenes/"+years; //variable a pasar
document.getElementeById('formr').action = route
Since location.href
is an environment variable, it is the browser that deals with it. Do not jade