cancel
Showing results for 
Search instead for 
Did you mean: 

user sorting on ftl template

trelofysikos
Champ in-the-making
Champ in-the-making
I would like the user to be able to sort documents on my template by clicking on the row title.

to do this i' m using links on the row title that pass an variable on the url, like this
<a href="/alfresco/navigate/browse/workspace/SpacesStore/${space.id}?sort=id">ID</a>

on the FTL i' m trying to get this variable by using this code
<#assign keys = args?keys>
<#list keys as arg>    
   ${arg}
</#list> 

but it is not working. I have also tried
<#assign keys = sort?keys>
<#list keys as arg>    
   ${arg}
</#list> 

How can i get this variable from the url ? Is there an error in the link url?
15 REPLIES 15

luxoliver
Champ in-the-making
Champ in-the-making
What are you doing exactly ?
Did you use a web script, a JavaScript and a ftl to do what you wont ?
Are you a newbe ?

trelofysikos
Champ in-the-making
Champ in-the-making
I am making a custom view for a space and using freemarker to do this.
My custom view is working fine but would also like to add sorting capabilities like the alfresco browse.
I am quite a noob but have learned much lately.

Can you help me out ? ( or are you just curious ? Smiley Tongue )

luxoliver
Champ in-the-making
Champ in-the-making
Normally for getting an URL argument we use javascript if it's an extension URL, you can insert it in your ftl like this <script> … </script>,
or if it' normal URL argument you can do it in freemarker <#if args.id?exists><#assign keys=args.id>
I'm not sure you can do that <#list keys as arg>. Maybe it's like that or something similar <#list keys.children as ard>

I hope that can help you

trelofysikos
Champ in-the-making
Champ in-the-making
what do you mean by normal URL ?
from my first post you can understand that my url will be something like
http://localhost:8080/alfresco/navigate/browse/workspace/SpacesStore/28ac2150-9767-43b5-ae79-3b2ae7d...

so to get the sort arg you suggest i try (i changed id from your code with sort.This is the argument, id is the value)
<#if args.sort?exists><#assign keys=args.sort></#if>

and I have already tried this and it doesn't work.

<#list … is fine. The error I get is before the debuger reaches there
Error during processing of the template 'Expression args is undefined on line xx, column x in workspace://SpacesStore/xxxxxx-xxxxxx-xxx-xxxx.'. Please contact your system administrator.

Have this worked for you ?
Is there another way i can take the arg from the url ? can you share some code?


Thanks

luxoliver
Champ in-the-making
Champ in-the-making
The error means that the argument doesn't exist.
This way work for me in a web script.
I think the best thing you have to do is that :
<script>
var test = url.extension;

"you can make modification of test"

</script>
Here test contain "28ac2150-9767-43b5-ae79-3b2ae7d01034?sort=id" or "sort=id" i don't know exactly in your case.
Now you just have to get the value "id".

Concerning your <#list… i don't understand how that can be fine if "keys" is empty ?

trelofysikos
Champ in-the-making
Champ in-the-making
by <#list is fine i mean i get an error before that. We have to deal with the other first and then i'll figure out how to do it.

I have also tried to get the arg from the url by javascript but can't assign this var to a freemarker var.
Do you know a way to do that?

luxoliver
Champ in-the-making
Champ in-the-making
To get the js var you can try to do something like that :
<script>
var test = url.extension;

model.testing= test;
</script>
<#if testing?exists>
<#list testing as keys>

</#list>
</#if>

I think that will work

trelofysikos
Champ in-the-making
Champ in-the-making
no, your code doesn't work, instead you can use this code to get the url parameters

<script type="text/javascript">
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
var asort = gup('sort');

//write the var on the document - just testing
document.write(sort);
</script>

But again i can't pass the javascript var to a freemarker var. I don't know if it is even possible to do this.

Maybe we're using the wrong approach here. Maybe we should use jsp or freemarker to get the url.
Any ideas on how to do that ?

luxoliver
Champ in-the-making
Champ in-the-making
Put the script in a javascript file (ex: myWebScript.get.desc.js).
My code work's well for me.

Good luke