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

eZ debug

Timing: Jan 19 2025 04:23:04
Script start
Timing: Jan 19 2025 04:23:04
Module start 'content'
Timing: Jan 19 2025 04:23:04
Module end 'content'
Timing: Jan 19 2025 04:23:04
Script end

Main resources:

Total runtime0.1779 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0058 588.9688180.8359
Module start 'content' 0.00580.0188 769.804797.9922
Module end 'content' 0.02460.1531 867.7969527.8047
Script end 0.1778  1,395.6016 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00331.8503200.0002
Check MTime0.00130.7278200.0001
Mysql Total
Database connection0.00060.365010.0006
Mysqli_queries0.116465.43551410.0008
Looping result0.00130.74121390.0000
Template Total0.152885.910.1528
Template load0.00140.792710.0014
Template processing0.151485.083710.1514
Override
Cache load0.00070.384510.0007
Sytem overhead
Fetch class attribute can translate value0.00080.431210.0008
XML
Image XML parsing0.00040.231110.0004
General
dbfile0.00372.0716200.0002
String conversion0.00000.003930.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs