Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Date format

Started by Muut Archive 11 years ago · 8 replies · 673 views
11 years ago

Hi can anybody suggest me a quick way to display the blog dates in a language other than english? I am using the antimatter blog skeleton. Thanks in advance.
Luca

11 years ago

The dates are formatted using the standard PHP date formatting syntax.

http://php.net/manual/en/function.date.php

You would just need to edit that syntax in the Twig template that renders the particular page. Probably templates/partials/blog_item.html.twig

11 years ago

Try this code (month names in Polish):
---php
<span class="list-blog-date">
{% set miesiace = ['Styczeń', 'Luty' , ' Marzec' , 'Kwiecień', 'Maj', 'Czerwiec', 'Lipiec', 'Sierpeiń', 'Wrzesień', 'Październik', 'Listopad', 'Grudzień'] %}
{% set nrMiesiaca = page.date|date("n") %}
{% set miesiac = miesiace[nrMiesiaca-1] %}

TWIG
        <span>{{ page.date|date("d") }}</span>
        <em>{{ miesiac }}</em>

    </span>

11 years ago

thanks to both, I'll try the solution Kuba Jarosz proposed, with names in italian (:D). I think we are missing a serious effort on internalization of grav

11 years ago

the thing worked perfectly, I'm posting it here for the Italians interested:

TWIG
      <span class="list-blog-date">
        {% set mesi = ['Gennaio', 'Febbraio' , 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre'] %}
        {% set nrMese = page.date|date("n") %}
        {% set mese = mesi[nrMese -1] %}
        <span>{{ page.date|date("d") }}</span>
        <em>{{ mese }}</em>
      </span>

Now I'll try to do something similar for the Archive snippet, any help is welcome

11 years ago

@lucam you must edit archives.html.twig template in user/plugins/archives/template/partials folder. My code (not ideal, but working):

---php
<ul class="archives">

{% set miesiace = ['Styczeń', 'Luty' , ' Marzec' , 'Kwiecień', 'Maj', 'Czerwiec', 'Lipiec', 'Sierpeiń', 'Wrzesień', 'Październik', 'Listopad', 'Grudzień'] %}

{% for month,items in archives_data %}
<li>
<a href="{{ base_url }}/archives_month{{ config.system.param_sep }},{{ month|date('M_Y')|lower|e('url') }}">
{% if archives_show_count %}
<span class="label">{{ items|length }}</span>
{% endif %}

TWIG
    {% set nrMiesiaca = month|date("n") %}        
    {% set miesiac = miesiace[nrMiesiaca-1] %}
    {% set rok = month|date("Y") %} 

    <span class="archive_date">{{ miesiac }} {{ rok }}</span>
    </a>
</li>

{% endfor %}
</ul>


11 years ago

worked perfectly! I attach the translated version for the Italian readers. Thanks again!
-```
<ul class="archives">

{% set mesi = ['Gennaio', 'Febbraio' , 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre'] %}

{% for month,items in archives_data %}
<li>
<a href="{{ base_url }}/archives_month{{ config.system.param_sep }},{{ month|date('M_Y')|lower|e('url') }}">

TWIG
    {% if archives_show_count %}
    <span class="label">{{ items|length }}</span>
    {% endif %}

    {% set nrMese = month|date("n") %}
        {% set mese = mesi[nrMese -1] %}
        {% set anno = month|date("Y") %}

    <span class="archive_date">{{ mese }} {{ anno }}</span>

  </a>
</li> 

{% endfor %}
</ul>

10 years ago

Muchas gracias. Lo he puesto en español en templates/partials/blog_item.html.twig en mi blog.
--- html
<span class="list-blog-date">
{% set meses = ['Enero', 'Febrero' , 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'] %}
{% set nrMeses = page.date|date("n") %}
{% set mes = meses[nrMeses -1] %}
<span>{{ page.date|date("d") }}</span>
<em>{{ mes }}</em>
<em>{{ page.date|date("Y") }}</em>
</span>

10 years ago

También lo he aplicado al plugín de búsqueda, en la plantilla de resultados simplesearch_item.html.twig en themes/antimatter/templates/partials.

Como se puede ver en esta página.

--- html
<span class="search-date">
{% set meses = ['Enero', 'Febrero' , 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'] %}
{% set nrMeses = page.date|date("n") %}
{% set mes = meses[nrMeses -1] %}
<span>{{ page.date|date("d") }}</span>
<em>{{ mes }}</em>
<em>{{ page.date|date("Y") }}</em>
</span>

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1359 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2956 9 years ago
Archive · by Muut Archive, 9 years ago
3 1121 9 years ago