Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
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.
We will now add the group and properties to the Home page and Blog post of the site.
This is done by using compositions to add the functionality in multiple places.
In the Settings section, expand the Document Type tree.
Open the Home
Document Type and select Compositions... in the top-right.
Choose the Open Graph
Document Type we created and Submit.
Save the Document Type.
This will add the group and properties from the Open Graph Document Type to the Home Document Type. Follow the same steps for the Blogpost
Document Type.
If you go to the content section and select Home you can now see your changes (the same goes for the blog posts).
With a few steps, we can add Open Graph to our pages.
Open Graph support will be added to the Homepage and Blog posts. It will be the minimum implementation of Open Graph containing the sites' title
, type
, URL
, and image
.
You will learn:
How to create a reusable set of properties (called Document Type compositions)
Add features based on where the composition is implemented
Get the URL for content items and media items
This lesson will teach you how to customize the Starter Kit.
A customized version of the site with your Home page image, site name, color theme, font, and perhaps a logo in the header.
Learn how to:
Navigate the editing area in the Content section.
Interact with content properties.
Upload images and use them with content items.
Preview your changes before publishing the content to the site.
Go to the Home page in the Content section.
Navigate to the Design group by scrolling down or selecting it from the dropdown menu.
Choose a different font and color theme.
Try different combinations and see what fits your site.
Save a draft of your changes by using ctrl
+s
or clicking the Save button. Save will not publish the changes to the website.
Click Save and preview to see how the page looks on different screen sizes.
Try changing the background image of the Home page.
Hover over the Hero Background thumbnail and click the red cross icon to remove the current image.
You can now click the '+' to open a dialog where you can choose an image from the Media library or upload a new image.
Select the image you want and click Submit in the lower right corner.
Find the Sitename property and change the name of the site.
This is shown in the site navigation menu.
If you want a logo instead of the Site Name you can upload and/or choose an image from the Media Library.
When you are happy with the changes publish them to the website by clicking the Save and Publish button.
To see the changes you've made go to the Info tab and click on the link.
Nice job! In this lesson, you've learned to navigate and edit properties on a page. You've also learned the difference between the Save, Preview, and Save and Publish actions and how to use them.
In 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 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.
Adding support for Open Graph can be done in many ways. In this lesson, we'll create a reusable set of properties we can add to specific page types.
First we need to see what the expected outcome will be. Open Graph for web pages needs to contain at least the following:
Looking at the above we can pull a couple of things out automatically and then add ways to input the rest.
In this lesson, we'll only add Open Graph Content of the type "website", so we don't need input for that. We can also get the URL for the page we are currently on. This leaves us with two remaining properties to add: title and image.
Go to the Settings section
Right-click on Document Types
Create a new Document Type without a template
Name the Document Type Open Graph
Create a group called Open Graph
Add a property to the group tab called Open Graph Title
Select Choose editor, search for textstring and add this to the tab.
Add another property named Open Graph Image and use the Media Picker editor.
Save the Document Type.
The final piece to the puzzle is adding the partial view that will be rendered when the composition is present. To do this:
Go to the Settings section
Right-click on Partial Views and choose Create... > New empty partial view
The partial view comes with a standard view model @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
. We are using compositions and only render this view on pages where the composition exists, which means we need to be a little more specific.
In the template editor, pass in the specific model you've created by adding <IOpenGraph>
.
Now you can start rendering the meta tags and adding in the values.
First add the title property
Set the cursor in the content attribute and select the + Insert... button.
Select Value...
Under Choose field, select the openGraphTitle
property.
Set the Default value to siteName
.
This will make sure that even though the Open Graph title isn't filled in, it will fallback to the title of the site
Check Yes, make it recursive to ensure the fallback will work on all pages.
Add the Open Graph meta tag for type of content - you can hardcode "website" in here:
Next up is adding the URL for Open Graph.
For this you'll need the entire URL to the page, not relative to this page.
There is a handy method for getting this from a content item. Add:
The final thing we need to do is render the image selected on the Open Graph Image property.
You'll still need to render the entire URL for the image.
First, we'll create a variable to get the image:
Next, we add the meta
property to get the path for the media item:
Your partial view is now complete and should only render on pages that are using the Open Graph composition.
The final view should look like this:
If you do not have Starter Kit installed, or experience issues with the properties not being picked up/showing up in HTML feel free to remove the fallback to siteName.
If your meta properties do not show up on social media, make sure to inspect source HTML. Make sure there are no inline HTML tags in og:title
, og:description
etc.
Pro tip: To keep the lesson short and to the point, we have left out null
-checks from the code examples. So remember to fill in the Open Graph properties, in the content section, to avoid exceptions when viewing the page.
If you need some help, here's where to find it.
You're a registered user of the developer community website, known as "Our".
Maybe you have even signed up to attend a local meetup!
Register on our.umbraco.com.
Search the forum, or browse the extensive documentation if you prefer more structured learning.
Please create a forum post if you don't know the best way to proceed. There are experienced community members online 24/7 so hopefully you won't have to wait long for a reply. We are always very excited to help out newcomers!
Check the home page of Our for any upcoming meetups near you. If there aren't any, keep an eye out for any online community hangouts happening soon.
Finally, do think about contributing yourself. Even if it's pointing out something in the documentation that could be made clearer, we'd love to hear from you.
Welcome, you are now a valued member of the Umbraco community!
All done, great job! Now test out if it works. Try adding it to more document types. Remember this is only one way of adding this functionality. You might want additional Open Graph tags or the properties to be on a different tab (e.g. Navigation or SEO).
In this lesson, you have learned:
To create a Document Type composition
How to create and render a Partial view
Compositions create an interface you can check on and use as a page model (IOpenGraph
)
How to get the full path (absolute URL) for both content and media items.
Next step is to get the Open Graph code rendered on the website. This is done in the head
section of the HTML, so you need to find the template for this.
In the Starter Kit
the head is placed in the Master Template, which is responsible for wrapping all the other templates.
Because you've added the Open Graph feature as a composition you can check if the composition is present on the current page and then render meta tags.
Go to the Settings section and expand the Template tree.
Select the Master template
Find the <head>
HTML tags at the top of the Template
Write the following before the closing </head>
tag:
This will render a partial view if the composition is present on the current page. Currently that is the case for Home and Blog posts on the site.
IOpenGraph
is an interface created by adding the composition. When you know how that works you can see how powerful it can be. If not, enjoy the handy helper to check for the composition.
At the end, the head should look like this: