[dancer-users] interpolate a Javascript variable as to assign it's value to a TT variable
Nikos Vaggalis
nikos.vaggalis at gmail.com
Tue Sep 8 23:13:12 BST 2015
More educational value out of this question than a practical one
Is it possible to interpolate a Javascript variable as to assign it's value
to a TT variable?
The scenario would be that from within the materialized template to extract
value pairs from DOM elements like sliders,select groups etc,serialize them
and save the resulting string into a cookie:
<script>
var getvalue = $(
"#Brand").find(":selected").parent("optgroup").attr("label");
jsvar = {Brand:getvalue};
jsvar = JSON.strignify(jsvar);
[% SET session.ttvar= jsvar ]%
</script>
Imagine going through a series of elements,capturing the values which can
be used later on as parameters to a POST call i.e
{Brand:...,Price_from....,Price_to:...}
since they would be saved in a cookie which would be valid for the rest of
the session, they could be reused by the same or another route for
purposes of for example reinstating or remembering the previous state after
the back button of the browser is hit
Of course, that could be done with an Ajax call but been thinking of
alternative ways
So the problem here is how do you escape out of the TT context and inject
temporary Javascript context in [% SET session.ttvar= jsvar %] ,so that
jsvar gets assigned to ttvar
?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20150909/2e989e50/attachment.html>
More information about the dancer-users
mailing list