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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Set date format per language in blog post

Solved by Karmalakas View solution

Started by Ton Haarmans 5 years ago · 5 replies · 862 views
5 years ago

In the file blog_item.html.twig I have now this line:
<span><i class="fa fa-clock-o"></i> {{ child.header.date|date('d') }} {{ 'GRAV.MONTHS_OF_THE_YEAR'|ta(child.header.date|date('n') - 1) }} {{ child.header.date|date('Y') }}</span>
This translates the names of the months brilliantly and in Dutch the date format is correct. In the English blog posts it is not: the day number should then be behind the name of the month. So perhaps there is a way to do something like this?:
{% if language.current = english %}
do this
{% else %}
do that
...

5 years ago

@TonHaarmans, What have you tried so far? Your suggestion doesn't seem to be too difficult to give it a go...

5 years ago

I tried this:

{% if language.current == nl %}
<span><i class="fa fa-clock-o"></i> {{ child.header.date|date('d') }} {{ 'GRAV.MONTHS_OF_THE_YEAR'|ta(child.header.date|date('n') - 1) }} {{ child.header.date|date('Y') }}</span>
{% endif %}
{% if language.current == en %}
<span><i class="fa fa-clock-o"></i> {{ 'GRAV.MONTHS_OF_THE_YEAR'|ta(child.header.date|date('n') - 1) }} {{ child.header.date|date('d') }} {{ child.header.date|date('Y') }}</span>
{% endif %}

It doesn't give an error, but it also does not work. I don't even know if there is something like {% if language.current == en %}. I'm just guessing...

5 years ago Solution

Try this:

TWIG
{% if grav.language.getActive is same as('nl') %}
    <...>
{% elseif grav.language.getActive is same as('en') %}
    <...>
{% endif %}

I think I'll try to make a simple plugin for this purpose after work :) I'll need it at some point anyway

5 years ago

Check this plugin I just created ;)

Keep in mind it's tested only on my local with two languages and only a few cases. If you try and find some problems, don't hesitate to open an issue ;)

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 125 19 hours ago
General · by pamtbaau, 1 day ago
1 89 24 hours ago
General · by Andy Miller, 2 days ago
0 73 2 days ago
General · by Marcel, 12 months ago
6 382 5 days ago
General · by Duc , 6 days ago
3 69 6 days ago