.. include:: _include.rst .. highlight:: jinja .. _template_custom_filters: ############## Custom Filters ############## |asa2| provides custom filters specialized for the use with WordPress. Custom filters behave exactly like the :ref:`template_filters`. They must be appended to a placeholder with a pipe (|) like in this example: .. code:: {{ Title|custom_filter }} .. _filter_divide: ****** divide ****** The filter ``divide`` divides an array into parts. The number of parts is defined by the argument. This filter makes it easy to display array data in a column design. The example divides the product Features into three parts and uses two for loops (:ref:`for_loop`) to display the result in a three column design. .. code::
{% for part in FeaturesArray|divide(3) %}
{% endfor %}
.. _filter_get_key: ******* gallery ******* This is a special filter for placeholder :ref:`placeholder_ImageSets`. It allows to create HTML formatted lists of an item's product images. For more details see :ref:`placeholder_ImageSetsArrayGallery`. ******* get_key ******* You can extract a value from array data by using the custom filter ``get_key``. It takes an array key as parameter and returns its value. ``get_key`` works recursive through multidimensional arrays. If the key does not exits an empty string will be returned. This example will retrieve the second element of the product's set of images: .. code:: {{ ImageSetsArray|get_key(2) }} If you have serialized data, for example in a custom field, you can combine ``get_key`` with :ref:`filter_unserialize`: .. code:: {{ repo_custom_field_serialized_array|unserialize|get_key("some_key") }} .. _filter_unserialize: *********** unserialize *********** The filter ``unserialize`` comes in handy when you are dealing with serialized data, for example in Repo :ref:`repo_adv_custom_fields`: So to use the serialized data you first have to **unserialize** the string and transform it into a list (array) you can work with. .. code:: {{ repo_custom_field_serialized_array|unserialize }} For reusability we can put the list data in a temporary variable, e.g. ``my_list_data``, by using the **set** function. .. code:: {% set my_list_data = repo_custom_field_serialized_array|unserialize %} Now you can use the varialbe ``my_list_data`` with array filters, like :ref:`filter_get_key`: .. code:: {{ my_list_data|get_key("some_key") }}