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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 22:36:30
Script start
Timing: Jan 18 2025 22:36:30
Module start 'layout'
Timing: Jan 18 2025 22:36:30
Module start 'content'
Timing: Jan 18 2025 22:36:31
Module end 'content'
Timing: Jan 18 2025 22:36:31
Script end

Main resources:

Total runtime1.3725 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0073 587.9141152.6250
Module start 'layout' 0.00730.0030 740.539139.4609
Module start 'content' 0.01031.3604 780.0000559.5703
Module end 'content' 1.37070.0017 1,339.570312.1641
Script end 1.3724  1,351.7344 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00300.2180160.0002
Check MTime0.00120.0882160.0001
Mysql Total
Database connection0.00100.070310.0010
Mysqli_queries1.313995.7357570.0231
Looping result0.00050.0334550.0000
Template Total1.340597.720.6703
Template load0.00210.151320.0010
Template processing1.338497.521220.6692
Template load and register function0.00010.006610.0001
states
state_id_array0.00090.065510.0009
state_identifier_array0.00170.126220.0009
Override
Cache load0.00170.1239420.0000
Sytem overhead
Fetch class attribute can translate value0.00060.043220.0003
Fetch class attribute name0.00090.067450.0002
XML
Image XML parsing0.00100.072820.0005
class_abstraction
Instantiating content class attribute0.00000.000860.0000
General
dbfile0.00110.0828240.0000
String conversion0.00000.000640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
10content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 26
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs