Forums / Setup & design / Using view_parameters for sort

Using view_parameters for sort

Author Message

Fraser Hore

Sunday 16 October 2005 8:26:54 am

I'm trying to use view_parameters to pass parameters from the url to the "sort_by" value in the fetch but can't seem to get it to work. here's my code:

<a href="http://localhost/corporate/organizations/(sort_direction)/true()" title="Sort Ascending">
Sort Ascending</a><p>

<a href="http://localhost/corporate/organizations/(sort_direction)/false()" title="Sort Descending">
Sort Descending</a><p>

Current sort value: {$view_parameters.sort_direction'}<p>

{def $nodes=fetch( 'content', 'list', hash( 'parent_node_id', $node.node_id, 'sort_by', array( 'attribute', $view_parameters.sort_direction,'organization/organization_name' ) ) )}

{foreach $nodes as $node}
{$node.name} <p>
{/foreach}

{undef $nodes}

Clicking on the links changes the value that appears in the URL and the value printed on the page, but it doesn't change the sort order of the list of organizations. If I hard code true() or false() into the sort_by parameter value field the list does sort properly.

I did do quite a bit of searching on the forum for this one and that's how i got this far. Any suggestions for what might be the problem would be much appreciatd.

Cheers,

Fraser

Marko Žmak

Sunday 16 October 2005 9:02:13 am

Hi Fraser!

What you are doing wrong here is that you misunderstood what true() and false() eZ operators do...

They actually return the true or false value of type boolean, they DON'T return the "true()" or "false()" strings.

In your <A> tag:

<a href="http://localhost/corporate/organizations/(sort_direction)/true()" title="Sort Ascending">

you actually put the string value "true()" as value for sort_direction parameter so when you fetching code:

{def $nodes=fetch( 'content', 'list', hash( 'parent_node_id', $node.node_id, 'sort_by', array( 'attribute', $view_parameters.sort_direction,'organization/organization_name' ) ) )}

comes to the $view_parameters.sort_direction it gets the string value "true()" and not the boolean value as returned from true() opetator.

A sollution to your problem could be:

1) Make the <A> tag like this:

<a href="http://localhost/corporate/organizations/(sort_direction)/{true()}" title="Sort Ascending">

So the return value from the true() function will be set as sort_direction value. I'm not sure if this will work, but I think it should.

2) If the first sollution fails you could make the <A> tag like this:

<a href="http://localhost/corporate/organizations/(sort_direction)/1" title="Sort Ascending">

(or 0 for the false() case)
and then manually adjust the value of some variable to true() or false() depending of the value of $view_parameters.sort_direction. But try the 1st sollution first.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Fraser Hore

Sunday 16 October 2005 9:12:42 am

Your first option worked! Thanks so much! I really appreciate the help!

Cheers,

Fraser