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 Jan 7 at 14:21
David LozziDavid Lozzi
549
549
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
Jan 7 at 15:19
D'oh, that got me again. Thank you!
– David Lozzi
Jan 7 at 15:27
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
Jan 7 at 14:44
2
Funny enough this didn't work, I was trying this before until someone else pointed me to the fact that the formatting should work above. Thanks for posting!
– David Lozzi
Jan 7 at 15:28
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
Jan 7 at 15:19
D'oh, that got me again. Thank you!
– David Lozzi
Jan 7 at 15:27
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
Jan 7 at 15:19
D'oh, that got me again. Thank you!
– David Lozzi
Jan 7 at 15:27
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 Jan 7 at 14:41
answered Jan 7 at 14:33
KevinKevin
17.8k848108
17.8k848108
This is much better than my answer!
– hotwebmatter
Jan 7 at 15:19
D'oh, that got me again. Thank you!
– David Lozzi
Jan 7 at 15:27
add a comment |
This is much better than my answer!
– hotwebmatter
Jan 7 at 15:19
D'oh, that got me again. Thank you!
– David Lozzi
Jan 7 at 15:27
This is much better than my answer!
– hotwebmatter
Jan 7 at 15:19
This is much better than my answer!
– hotwebmatter
Jan 7 at 15:19
D'oh, that got me again. Thank you!
– David Lozzi
Jan 7 at 15:27
D'oh, that got me again. Thank you!
– David Lozzi
Jan 7 at 15:27
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
Jan 7 at 14:44
2
Funny enough this didn't work, I was trying this before until someone else pointed me to the fact that the formatting should work above. Thanks for posting!
– David Lozzi
Jan 7 at 15:28
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
Jan 7 at 14:44
2
Funny enough this didn't work, I was trying this before until someone else pointed me to the fact that the formatting should work above. Thanks for posting!
– David Lozzi
Jan 7 at 15:28
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 Jan 7 at 14:30
hotwebmatterhotwebmatter
459112
459112
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
Jan 7 at 14:44
2
Funny enough this didn't work, I was trying this before until someone else pointed me to the fact that the formatting should work above. Thanks for posting!
– David Lozzi
Jan 7 at 15:28
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
Jan 7 at 14:44
2
Funny enough this didn't work, I was trying this before until someone else pointed me to the fact that the formatting should work above. Thanks for posting!
– David Lozzi
Jan 7 at 15:28
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
Jan 7 at 14:44
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
Jan 7 at 14:44
2
2
Funny enough this didn't work, I was trying this before until someone else pointed me to the fact that the formatting should work above. Thanks for posting!
– David Lozzi
Jan 7 at 15:28
Funny enough this didn't work, I was trying this before until someone else pointed me to the fact that the formatting should work above. Thanks for posting!
– David Lozzi
Jan 7 at 15:28
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.
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