Add a Blog Post Publication Date
Last updated
Last updated
In , we displayed a nicely formatted publication date on the blog post page.
Finally, in Part Three we shall change the blog listing.
In the Settings section, expand the Partial Views > Components > LatestBlogPosts folder.
Select Default.cshtml.
Scroll down to find the foreach
loop.
Declare a new publicationDate
variable as the first thing within the loop:
Locate the blogpost-date
element a bit further down and change it to use the new variable:
The ToLongDateString() method is called on the publicationDate
variable to format it as a long date string.
Redefine the blogposts
variable before the first div
tag - this will be used for sorting the posts:
Because we are sorting by a custom property we need to use the generic Value
method.
Locate the @foreach
loop, and change Model.Blostposts
to the variable created above: blogposts
:
Save the partial view - a confirmation message should appear confirming that the Partial view has been saved.
Now view both the Blog overview and the blog posts themselves in the browser to confirm that all is working as expected.
Nice job! In this lesson, you've learned what a Document Type is and how to add a new Property to it. You've also learned how to change Templates and sort by custom Properties.