My Date in Twig is ignoring format
I have a twig file with the following code in my Drupal 8.4.4 site:
<div class="value col-md-12">{{ node.field_date.value }}</div>
And in my content type, manage display option, I have it formatted like this:
But on the website, it shows the date as
2019-01-16T23:00:00
What am I missing?
datetime
add a comment |
I have a twig file with the following code in my Drupal 8.4.4 site:
<div class="value col-md-12">{{ node.field_date.value }}</div>
And in my content type, manage display option, I have it formatted like this:
But on the website, it shows the date as
2019-01-16T23:00:00
What am I missing?
datetime
add a comment |
I have a twig file with the following code in my Drupal 8.4.4 site:
<div class="value col-md-12">{{ node.field_date.value }}</div>
And in my content type, manage display option, I have it formatted like this:
But on the website, it shows the date as
2019-01-16T23:00:00
What am I missing?
datetime
I have a twig file with the following code in my Drupal 8.4.4 site:
<div class="value col-md-12">{{ node.field_date.value }}</div>
And in my content type, manage display option, I have it formatted like this:
But on the website, it shows the date as
2019-01-16T23:00:00
What am I missing?
datetime
datetime
asked 1 hour ago
David Lozzi
329
329
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You are printing the node value directly, which is bypassing the field formatter and other things (since you are not using the render array).
Do this instead:
{{ content.field_date }}
This will render normally and ensure field formatter settings are respected.
This is much better than my answer!
– hotwebmatter
6 mins ago
add a comment |
Try piping the value to twig's date
function:
https://twig.symfony.com/doc/2.x/filters/date.html
That approach might give you something like this:
<div class="value col-md-12">{{ node.field_date.value | date("D M j G:i T") }}</div>
1
I guess technically this would work, but you lose the ability to change the format on the fly from the admin. It would also print the div out, regardless of if there is a value in the field or not.
– Kevin
41 mins ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "220"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f274744%2fmy-date-in-twig-is-ignoring-format%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are printing the node value directly, which is bypassing the field formatter and other things (since you are not using the render array).
Do this instead:
{{ content.field_date }}
This will render normally and ensure field formatter settings are respected.
This is much better than my answer!
– hotwebmatter
6 mins ago
add a comment |
You are printing the node value directly, which is bypassing the field formatter and other things (since you are not using the render array).
Do this instead:
{{ content.field_date }}
This will render normally and ensure field formatter settings are respected.
This is much better than my answer!
– hotwebmatter
6 mins ago
add a comment |
You are printing the node value directly, which is bypassing the field formatter and other things (since you are not using the render array).
Do this instead:
{{ content.field_date }}
This will render normally and ensure field formatter settings are respected.
You are printing the node value directly, which is bypassing the field formatter and other things (since you are not using the render array).
Do this instead:
{{ content.field_date }}
This will render normally and ensure field formatter settings are respected.
edited 44 mins ago
answered 52 mins ago
Kevin
17.5k848108
17.5k848108
This is much better than my answer!
– hotwebmatter
6 mins ago
add a comment |
This is much better than my answer!
– hotwebmatter
6 mins ago
This is much better than my answer!
– hotwebmatter
6 mins ago
This is much better than my answer!
– hotwebmatter
6 mins ago
add a comment |
Try piping the value to twig's date
function:
https://twig.symfony.com/doc/2.x/filters/date.html
That approach might give you something like this:
<div class="value col-md-12">{{ node.field_date.value | date("D M j G:i T") }}</div>
1
I guess technically this would work, but you lose the ability to change the format on the fly from the admin. It would also print the div out, regardless of if there is a value in the field or not.
– Kevin
41 mins ago
add a comment |
Try piping the value to twig's date
function:
https://twig.symfony.com/doc/2.x/filters/date.html
That approach might give you something like this:
<div class="value col-md-12">{{ node.field_date.value | date("D M j G:i T") }}</div>
1
I guess technically this would work, but you lose the ability to change the format on the fly from the admin. It would also print the div out, regardless of if there is a value in the field or not.
– Kevin
41 mins ago
add a comment |
Try piping the value to twig's date
function:
https://twig.symfony.com/doc/2.x/filters/date.html
That approach might give you something like this:
<div class="value col-md-12">{{ node.field_date.value | date("D M j G:i T") }}</div>
Try piping the value to twig's date
function:
https://twig.symfony.com/doc/2.x/filters/date.html
That approach might give you something like this:
<div class="value col-md-12">{{ node.field_date.value | date("D M j G:i T") }}</div>
answered 55 mins ago
hotwebmatter
457112
457112
1
I guess technically this would work, but you lose the ability to change the format on the fly from the admin. It would also print the div out, regardless of if there is a value in the field or not.
– Kevin
41 mins ago
add a comment |
1
I guess technically this would work, but you lose the ability to change the format on the fly from the admin. It would also print the div out, regardless of if there is a value in the field or not.
– Kevin
41 mins ago
1
1
I guess technically this would work, but you lose the ability to change the format on the fly from the admin. It would also print the div out, regardless of if there is a value in the field or not.
– Kevin
41 mins ago
I guess technically this would work, but you lose the ability to change the format on the fly from the admin. It would also print the div out, regardless of if there is a value in the field or not.
– Kevin
41 mins ago
add a comment |
Thanks for contributing an answer to Drupal Answers!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f274744%2fmy-date-in-twig-is-ignoring-format%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown