I'm using keystone.js with twig.js as template language. how can i change locale in date?
http://keystonejs.com/docs/database/#fieldtypes-date
I looked through all issues and stackoverflow questions and didn't find answer. in my template i write
{{ post._.publishedDate.format('D MMMM') }} and output is 9 July. I want it to be 9 июля in russian locale.
As far as I know, KeystoneJS use moment.js to set format on date. But how can i change momentjs locale? should i do this on my template or keystone.js or somewhere in middleware or keystone.js file?
I have tried this:
{{ post._.publishedDate.locale('ru').format('D MMMM') }}
{{ post.publishedDate.locale('ru').format('D MMMM') }}
{{ post._.publishedDate.format('D MMMM', 'ru') }}
{{ post._.publishedDate.format('D MMMM', 'ru') }}
{{ post.publishedDate.parse('Do MMM YYYY') }}
{{ _.format(post.publishedDate, 'D MMM') }}
Also i tried in keystone.js file set local variable moment = require('moment') and then in template
{{ moment(post.publishedDate).locale('ru').format('D MMMM') }}
And it didn't work too. What I'm doing wrong?
I can't understand how KeystoneJS work with momentjss and what should I do.
this documentation part is not very helpful.
I think you can set default language for whole site as.
// keystone.js
var moment = require('moment');
moment.locale(locale);
Related
I am running Timber framework on a Wordpress site and in my twig file I have the following code:
<div {{ fn('post_class', ['cell', 'small-12', 'medium-6', 'large-' ~ productTabW, 'xlarge-' ~ productW] ) }}>
On one server it outputs the correct:
<div class="cell small-12 medium-6 large-8 xlarge-6 post-66840 product type-product status-publish has-post-thumbnail product_cat-... ">
On another server I get this:
<divclass="cell small-12="" medium-6="" large-8="" xlarge-6="" post-66835="" product="" type-product="" status-publish="" has-post-thumbnail="" product_cat-....>
You will note the space is removed between the div and class and it looks like the array is expecting key value. The code is the same so I am wondering what php configuration would make Timber output this behaviour.
This was a problem with an outdated Timber installation for PHP 7.4. Updating Timber through composer solved the issue.
in a form i would like modify my url when i change my select option.
When i do this, i have this in my url :
?extension-filter=&extension-list=1019
And i try to get 'extension-list' for give this parameter in my path.
Something like this is possible ? :
<form action="{{ path('my_path', {myoption : app.request.attributes.get('_extension-list') }) }}
You can retrieve a param in query string as follow:
app.request.get('_extension-list')
Hope this help
I was just going through the bolt template for _recordfooter , in the default theme and came across the following liens of code:
{{ __('general.phrase.written-by-on', {
'%name%': record.user.displayname|default(__('Unknown')),
'%date%': record.datepublish|localedatetime("%A %B %e, %Y")
}) }}
I am not quite understanding what the above line of code is really doing and most of all i am not understanding what the usage of the double underline function and also what exactly is 'general.phrase.written-by-on' and where is it coming from ??
They are keyword in the base translation file, in the loacle specific directory under vendor/bolt/bolt/app/resources/translations/
We have multiple environments for our apps, and I am trying to use generic consul template and an environment variable to create haproxy configurations for different environments.
This is what I am trying to do:
{{$environment := "yellow" }}
....
balance leastconn {{range service "myservice-{{$env}}"}}
....
I cannot seem to find a way to use this variable within this range. Is there a way to get this working?
Thanks!
You just need to define the variable and then use it in the range statement.
{{ $service_name := env "CONSUL_SERVICE_NAME" }}
{{range service $service_name }}
I started working on a project using Silex and Twig and now I'm trying to set up translations. I registered TranslationServiceProvider before TwigServiceProvider
and basically this work's:
{{ app.translator.trans('Homepage') }}
but this doesn't:
{{ 'Homepage'|trans }}
and it returns the following error:
Twig_Error_Syntax in ExpressionParser.php line 573: The filter
"trans" does not exist in "homepage.twig" at line 6
I have read the Silex documentation stating that
when using the Twig bridge provided by Symfony (see
TwigServiceProvider), you will be allowed to translate strings in the
Twig way
but I still don't understand what I am doing wrong and how does the trans filter work.
In my particular case, the issue was that I did not have, twig-bridge declared in composer.json:
"require": {
"silex/silex" : "1.2.2",
"symfony/twig-bridge" : "~2.3",
"twig/twig" : "1.16.2"
}
only silex and twig.