1

I have this code in .vm file

<script...>
.....
var attr = attr0[i].id;
</script....>

#set($attr1 = $request.getParameter("attr"))
$attr1

How to get the jquery attribute (which is clientside) to velocity template variable which is serverside?

Drozzy
  • 71
  • 1
  • 8
  • 1
    You can't. As you say jquery is clientside and velocity is serverside. If you want to pass something from the dom to your template you have to do a new request, passing what you need as parameter. – Marco Mercuri Jan 12 '17 at 15:34
  • Thanks Marco. How to make new request, can you please point me to some documentation? – Drozzy Jan 12 '17 at 22:14
  • Is this velocity template part of web content,theme or layout,for better clarity on what are the available variables for the same? – Shivam Aggarwal Feb 03 '17 at 06:46

1 Answers1

0

As I suggested in my comment you can use a parameter, something like this:

  1. In your template get the entire current URL (URL + parameter)
  2. Check for your parameter (es. attr)
    1. If ther is the attr parameter and it has a value do something in your template
  3. In your script create a variable with your current URL and append your parameter to it (es. var url = {$currentURL} + '?attr=attrValue')
  4. Now you have just to call this URL.
Marco Mercuri
  • 1,117
  • 9
  • 17