Browse Source

Merge pull request #1390 from tiagojsag/list_date_format

Custom date and datetime formats in list
Thomas 12 years ago
parent
commit
3835c3eb98

+ 5 - 2
Resources/doc/reference/field_types.rst

@@ -9,8 +9,8 @@ There are many field types that can be used in the list action or show action :
 * array: display value from an array
 * array: display value from an array
 * boolean: display a green or red picture dependant on the boolean value, this type accepts an ``editable``
 * boolean: display a green or red picture dependant on the boolean value, this type accepts an ``editable``
   parameter to edit the value from within the list or the show actions
   parameter to edit the value from within the list or the show actions
-* date: display a formatted date
-* datetime: display a formatted date and time
+* date: display a formatted date. Accepts an optional ``format`` parameter
+* datetime: display a formatted date and time. Accepts an optional ``format`` parameter
 * text: display a text
 * text: display a text
 * trans: translate the value with a provided ``catalogue`` option
 * trans: translate the value with a provided ``catalogue`` option
 * string: display a text
 * string: display a text
@@ -25,6 +25,9 @@ There are many field types that can be used in the list action or show action :
     
     
     Option for currency type must be an official ISO code, example : EUR for "euros".
     Option for currency type must be an official ISO code, example : EUR for "euros".
     List of iso code : http://en.wikipedia.org/wiki/List_of_circulating_currencies
     List of iso code : http://en.wikipedia.org/wiki/List_of_circulating_currencies
+    
+    In ``date`` and ``datetime`` field types, ``format`` pattern must match twig's
+    ``date`` filter specification, available at: http://twig.sensiolabs.org/doc/filters/date.html
 
 
 More types might be provided based on the persistency layer defined. Please refer to their
 More types might be provided based on the persistency layer defined. Please refer to their
 related documentations.
 related documentations.

+ 2 - 0
Resources/views/CRUD/list_date.html.twig

@@ -14,6 +14,8 @@ file that was distributed with this source code.
 {% block field%}
 {% block field%}
     {%- if value is empty -%}
     {%- if value is empty -%}
          
          
+    {%- elseif field_description.options.format is defined -%}
+        {{ value|date(field_description.options.format) }}
     {%- else -%}
     {%- else -%}
         {{ value|date('F j, Y') }}
         {{ value|date('F j, Y') }}
     {%- endif -%}
     {%- endif -%}

+ 2 - 0
Resources/views/CRUD/list_datetime.html.twig

@@ -14,6 +14,8 @@ file that was distributed with this source code.
 {% block field %}
 {% block field %}
     {%- if value is empty -%}
     {%- if value is empty -%}
          
          
+    {%- elseif field_description.options.format is defined -%}
+        {{ value|date(field_description.options.format) }}
     {%- else -%}
     {%- else -%}
         {{ value|date }}
         {{ value|date }}
     {%- endif -%}
     {%- endif -%}

+ 2 - 0
Resources/views/CRUD/show_date.html.twig

@@ -14,6 +14,8 @@ file that was distributed with this source code.
 {% block field%}
 {% block field%}
     {%- if value is empty -%}
     {%- if value is empty -%}
          
          
+    {%- elseif field_description.options.format is defined -%}
+        {{ value|date(field_description.options.format) }}
     {%- else -%}
     {%- else -%}
         {{ value|date('F j, Y') }}
         {{ value|date('F j, Y') }}
     {%- endif -%}
     {%- endif -%}

+ 2 - 0
Resources/views/CRUD/show_datetime.html.twig

@@ -14,6 +14,8 @@ file that was distributed with this source code.
 {% block field %}
 {% block field %}
     {%- if value is empty -%}
     {%- if value is empty -%}
          
          
+    {%- elseif field_description.options.format is defined -%}
+        {{ value|date(field_description.options.format) }}
     {%- else -%}
     {%- else -%}
         {{ value|date }}
         {{ value|date }}
     {%- endif -%}
     {%- endif -%}