Author
|
Message
|
Mindshare Interactive Campaigns
|
Wednesday 13 September 2006 8:17:24 am
I have a custom class with a multiple selection attribute named <b>Country</b>. This attribute lists several countries listed in no particular order. This code is being used to display it as a dropdown:
<select name="study_country">
<option value="-99" selected>Please select a country...</option>
<option disabled> </option>
{def $countries = fetch('content', 'class_attribute', hash('attribute_id', 308))}
{foreach $countries.content.options as $dropdown_item}
<option>{$dropdown_item.name}</option>
{/foreach}
</select>
This displays the countries in whatever order they are listed in the class definition. I need these to be sorted alphabetically. <b>fetch('content', 'class_attribute')</b> does not seem to allow this. How can I accomplish this?
http://www.mindshare.net
|
Claudia Kosny
|
Thursday 14 September 2006 11:19:34 am
Hello there
As far as I know there is no inbuilt way to do this. The easy way out is to fetch all the country names in an array, sort this array and then loop through this array. Unfortunately there is no array sort function built into EZ so either take the contribution
http://ez.no/community/contribs/template_plugins/arraysortoperator or just write your own wrapper for the php sort function. Greetings from Luxembourg Claudia
|
Mindshare Interactive Campaigns
|
Friday 15 September 2006 12:12:52 pm
Thank you for the suggestion Claudia. I installed the extension and rewrote the code above like so:
{def $country_array = array("foo")}
{def $countries = fetch('content', 'class_attribute', hash('attribute_id', 308))}
{foreach $countries.content.options as $dropdown_item}
{set $country_array = $country_array|append($dropdown_item.name)}
{/foreach}
{set $country_array = $country_array|remove(0,1)}
{def $sorted_country_array = $country_array|sort('string')}
<select name="study_country">
<option value="-99" selected>Please select a country...</option>
<option disabled> </option>
{foreach $sorted_country_array as $sorted_country}
<option>{$sorted_country}</option>
{/foreach}
</select>
This bit of code presents the list of attributes in the same order; i.e. the arraysortoperator extension is doing nothing. I noticed that the extension's description page states that it works with version 3.6 and 3.7, but I am using 3.8. Any idea what is going wrong?
http://www.mindshare.net
|
Claudia Kosny
|
Friday 15 September 2006 1:18:57 pm
Hi there The sort operator of this extension works fine for me (EZ 3.8.3). Are you sure that the extension is loaded alright? If not you should see an message in the debug output that the operator sort is not defined. Another possible thhough unlikely problem might be interference from another extension which might already implement an sort operator wich behaves differently. Greetings from Luxembourg Claudia
|
Mindshare Interactive Campaigns
|
Wednesday 20 September 2006 7:23:45 am
Good thinking. I turned on the debug output and found this line:
Warning: eZTemplate Sep 20 2006 17:19:51
Operator 'sort' is not registered
This is confusing though because the extension is registered in the admin screen. I tried both registering it manually by updating the necessary .ini files as well as using the Setup -> Extension form. Am I missing a step?
http://www.mindshare.net
|
Claudia Kosny
|
Wednesday 20 September 2006 7:42:11 am
Hi there Maybe the directry structure if the extension is not correct - this happens quite often to me if I unzip into a directory with the name of the extension and the zipfile provides already such a directory. So check your extensions folder and open the folder for the array sort extension. There you should see the folders autoloads and maybe settings (I already deleted the extension again so I am not sure). Claudia
|
Mindshare Interactive Campaigns
|
Wednesday 20 September 2006 10:36:26 am
Claudia, you're brilliant! I never considered that the files were not unzipped correctly. I went into the extension directory and found this:
|-extension
|---arraysortoperator
|-----docs
|-------autoloads
|-------classes
|-------settings
The <b>docs</b> directory contained the other directories, which is clearly wrong. The correct directory structure should look like this:
|-extension
|---arraysortoperator
|-----docs
|-----autoloads
|-----classes
|-----settings
Now my countries are sorted correctly. Thank you!
http://www.mindshare.net
|