Fork me on GitHub

smarty list alphabetically  Bottom

  • Anyone know how to use Smarty (pnrender) to list a set of links aphabetically? Right now they are just being listed by the order they were created, the newest ones being at the top. I would rather list them aphabetically. Any input would greatly be appreciated.

    EDIT:

    Here is a snippet of my code:

    Code

    <!--[foreach from=$link_listing item=links]-->
                    <!--[if $links.category_name == "Corn"]-->
                <div class="box1">Corn</div>
                <div class="section">
                                <!--[foreach name=linkloop from=$links item=link]-->
                                <!--[if $link != $links.category_name]-->  
                    <div class="box2">        
                                    <a href="<!--[pnmodurl modname="pxPDFManager" type="user" func="downloadpdf" pdf_id="`$link.link_id`"]-->" target="_blank"><!--[$link.link_name]--></a>
                    </div>
                                <!--[/if]-->
                                <!--[/foreach]-->
                </div>
                    <!--[/if]-->
                    <!--[/foreach]-->
  • Mark West, any ideas? Im wanting to do the logic in the template, because its going going to be specific to a particular category within the module.
  • Really this sounds like application logic - i.e. something that should be done in PHP not in a template. However you could write your own plugin that does the sorting and assigns the value back to the template.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • Thanks for the reply mark. hmm, ok, now i just have to remember how to write a plugin. I did it awhile back for advprofile, hopefully it works close to the same way. Im surprised this isnt something i can do natively with Smarty.
  • I write sorting in at the API level. (ie, the results are sorted as they come out of the DB.) Works nice.
  • Again, i only want to do it for a particular category, i want this to be template level so that i can use it wherever i want. I appreciate the ideas guys, but its not what im looking for as it would require changing the core logic of the module and again would apply to all output, unless i hard coded it in the API.
  • So a simple plugin would do the job...

    In the template

    Code

    <!--[sort input=$myoriginalarray assign=mynewarray]-->


    and the plugin

    Code

    function smarty_function_sort($params, &$smarty)
    {
        extract($params);

        unset($params['input']);
        unset($params['assign']);
           
        if (!isset($input)) {
            $smarty->trigger_error("sort:  parameter 'input' required");
            return false;
        }    
        if (!isset($assign)) {
            $smarty->trigger_error("sort:  parameter 'assign' required");
            return false;
        }    

    /*php code to sort your array goes here
    see http://uk.php.net/manual/en/ref.array.php for vairous sorting options*/


        $smarty->assign($assign, $mysortedarray);
        return;
    }


    Notes: i've typed this directly into the forum so expect there to be typos. You'll also need to find the appropriate array sorting function or code a suitable sort rountine - the posted code is only basic plugin code.

    -Mark

    --
    Visit My homepage and Zikula themes.

This list is based on users active over the last 60 minutes.