symfony - Sort alphabetically with Twig -
i'm trying sort list of categories in alphabetical order. since more of php flaw i'm trying in way described here. don't have access core files of system need done twig tags.
the build in sort filter filters can't used when using numeric variable key in twig array. specific problem due use of array_merge php function
i'm trying incorporate code in link own code i'm not able done right.
i'm calling categories so:
{% category in shop.categories %} {{ category.title }} - {{ category.id }} {% endfor %}
if understand code correct should like:
{% set temparray = {} %} {% category in shop.categories %} numeric : {{ category.id }}, text : {{ category.title }} <br /> {% set temparray = temparray | merge({('_' ~ category.numeric):(category.text)}) %} {% endfor %} {% val in looparray %} {{ temparray['_' ~ val] }} <br/ > {% endfor %}
this doens't sort category names still category id's.
is there i'm missing?
forget link give (http://obtao.com/blog/2014/06/use-variable-key-twig-array/), it's bad source code doesn't sort array.
but have there : sorting in template, in symfony2: using twig sort collection of objects property
there no way sort array on category names in twig without create own filter. own filter sort , able use in twig templates.
==== not read if want know bad link ====
in bad link guy sort manually set order wants in line
{% set loopvalues = [10,20,30,40] %}
in fact post show that
{{ temparray[val] }} doesn't work val numeric
but works
{{ temparray['_'~val] }}
after dirty trick (but have work : {{ temparray[''~val] }} it's not important code give link useless...
Comments
Post a Comment