How do you retrieve current date for Symfony2 - symfony

I'm a newbie in Symfony 2 and i would like to know how do i get current date(today's date) from symfony2 and display in my twig.
Any kind souls willing to help?
Thank you very much

In twig
{{ 'now'|date('d - m -Y') }}

Related

My edit (CRUD) function remove some DATA when I use it

i've a problem with symfony project, in my Controller Company when I use edit function to modif some DATA with embedded form, symfony keep only 1 customer (first one) and what I was change and remove all other DATA.
I not understand why symfony do that.
Thank U for Ure help
Best regards
Try to use edit function in symfony with embedded form
You're using the wrong function to render the customer (and network and process) subforms, use form_row(customer) instead of form(customer):
{% for customer in form.customers %}
<h6 class="mt-5">Client
{{_key+1}}</h6>
{{ form_row(customer) }}{% endfor %}

Bolt modifying an record from the web page. Using Twig

Im trying to modify records from my wep page using bolt, for lets say an comment section. If someone posts an answer underneath an news item how do i put that info into an record. And if they want to edit their reaction how would I update it.
So i was trying something at this point with the status. My base status is always published.
{{ record.status == draft }} <-- tried this way
{% set record.status == record.status = draft %} <-- tried SET
{% set record.status == record.status = "draft" %} <-- tried adding ""
After my try and error period I went to all the documentation on bolt and twig. But I cant seem to find out how to do this.
So I hope someone knows how to do this, thank you in advance.
short anwser is - you can't modify database records directly from twig.
Twig it's template system (idea is to show data with it) .
To dwhat you want you need to write all this "stuff" by yourself . It can be done (best way is to learn about creating custom modules - but you need to be quite good with OOPHP , symfony components etc. )

How to get country language in Symfony

I'm customizing my error pages and I was wandering if it is possible to get the language of the country user directly in my template, without the controller.
You can use :
{{ app.request.locale }}
Edit
Ah i didn't understood the question but this is what you are looking for :
$request->getPreferredLanguage($anArrayOfYourSupportedLanguages);
Then pass it to your twig.
fabpot answer :
https://groups.google.com/forum/#!topic/symfony-devs/-2AwAQhlLLQ

How can I get timestamp value in Twig?

How can I get timestamp value in twig as I know date formatting is possible in twig but don't know how to get timestamp value using twig function;
There is other solution that might be easier to understand by designers.
{{ 'now'|date('U') }}
(I am aware that the question is already answered and it's old)
You can use this
{{ date().timestamp }}

How to display dateTime relative to the user location?

I am searching how to display the dateTime related to the user timezone using TWIG.
I really want to understand how it works.
Thank you.
There is no easy solution to get the user location in twig templates.
I would :
Try to get the user's timezone with Javascript
Store this value in a session
Then catch it with twig fron the {{ app.session }} object
Good luck ;)

Resources