In Part One we added a new property to the Blogpost Document Type. Now in Part Two, we're going to display that instead of the default creation date.
Find the blog posts on the Blog in the Content section.
Add publication dates to the blog posts.
Remember to publish your changes!
As this field is flagged as Mandatory you now can't save a post without it.
Go to the Settings section
Expand Templates, and Master, then click on Blogpost.
This is the template that is rendering the full page view of a blog post
Find the element with the blogpost-date
class and change it to use a nicely formatted Publication Date, i.e.:
Save the Template - a confirmation message should appear confirming that the Template was saved.
View the blog post page in the browser (find the page in the Content tree, then select the link on the Info tab).
In Part Two, 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 Partial View Macro Files.
Select LatestBlogPosts.cshtml.
Macros are beyond the scope of this lesson, but you don't need to understand them right now.
Scroll down to find the blogpost-date
element and change it to use a nicely formatted Publication Date, i.e.:
Further up in the view, you also need to redefine the blogposts
variable:
Because we are sorting by a custom property we need to use the generic Value
method.
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.
In this lesson, you will learn how to add a new date property to blog posts.
Content editors can specify the publication date for a blog post. Blog posts are displayed with the most recent publication date appearing first.
Learn how to:
Add a new property to a Document Type
Edit a Template to display the new property
Sort a list of items by a new property
In the Settings section, expand Document Types.
Click on Blogpost. This is the Document Type that defines the fields for this type of page.
The Document Type contains 2 groups: Content and Navigation & SEO.
At the bottom of the Content group select Add property.
This opens the Property Editor dialog window.
Give the property a name: Publication Date.
Give the property a description: The date of the blog post. This is the date used to display the most recent posts first..
Always try to add a meaningful description to help your editors.
Select Add editor to specify what type of data is being stored.
We need a standard date, so click on the Date Picker icon.
In the validation section, enable the field to make it mandatory.
Submit to close the dialog and save the property.
Select the Reorder option near the top-right of the window, then drag the new property to be after Page Title.
A logical order to your properties will make things easier for your editors.
Click I am done reordering near the top-right of the window and select Save the Document Type - a confirmation message should appear confirming that the Document Type was saved.