Articles and Article Items
Last updated
Last updated
Having a parent page with child pages provides a good example of Umbraco's features. For example, our fictional company, Widgets Ltd, publishes about ten articles per month and therefore wants the parent page to function as a blog. This setup works for articles, posts, and other collections that require multiple content items based on the same content type.
Create two new Document Types with template: Articles Main and Articles Item.
To create Articles Main Document Type, follow these steps:
Go to Settings.
Click ... next to the Document Types in the Settings tree.
Select Create....
Select Document Type with Template.
Enter a Name for the Document Type. Let's call it Articles Main.
Let's add two fields with the following specifications:
Intro
Articles Title
articlesTitle
Textstring
Intro
Articles Body Text
articlesBodyText
Rich Text Editor
Click Save
To create Articles Item Document Type, follow these steps:
Go to Settings.
Click ... next to the Document Types in the Settings tree.
Select Create....
Select Document Type with Template.
Enter a Name for the Document Type. Let's call it Articles Item.
Let's add two fields with the following specifications:
Content
Article Title
articleTitle
Textstring
Content
Article Content
articleContent
Rich Text Editor
Click Save
To add Articles Main as a child node:
Navigate to the Home Page Document Type.
Go to the Structure tab.
Select Choose in the Allowed child node types.
Select Articles Main.
Click Choose.
Click Save.
To update Articles Main Document Type permissions:
Navigate to the Articles Main Document Type.
Go to the Structure tab.
Select Choose in the Allowed child node types.
Select Articles Item.
Click Choose.
Click Configure as a collection.
Select List View - Content.
Click Save.
To add a content node:
Go to Content.
Select ... next to the HomePage node.
Click Create.
Select Articles Main.
Enter the name for the article. We are going to call it Articles.
Enter the content in the Article Title and Article Body Text fields.
Click Save and Publish. When you click on Save and Publish, you will notice an empty Collection is created.
We still need to add the child nodes which will be displayed in the Collection making it easier to view them. You can create new nodes from this section.
If you do not see the Collection, try refreshing the page.
Click Create Articles Item.
Enter the name for the article. We are going to call it Article 1.
Enter the content in the Article Title and Article Content fields.
Repeat steps 8 to 10 to create Article 2.
Click Save and Publish.
To update the Articles Main template, follow these steps:
Go to Settings.
Expand the Templates folder in the Templating section.
Open the Articles Main template.
Select Master in the Master template:No Master field.
Click Choose.
Click Save.
Open the Custom Umbraco Template folder.
Copy the contents of Blog.html.
Paste the content into Articles Main below the closing curly brace "}".
Remove everything from the <html>
(around line 8) to the end of the </div>
tag (around line 43) which is the header
and navigation
of the site since it is already mentioned in the Master template.
Remove everything from the <!-- Footer -->
tag (around line 83) to the end of the </html>
tag (around line 130)
Replace the static text within the <h1>
tags (around line 12) with the Model.Value reference to articlesTitle.
Replace the static text within the <div>
tags (from line 23 to 29) with the Model.Value reference to articlesBodyText.
Define a query for all articles below the <h3>
tag (around line 30) of the <!-- Latest blog posts -->
section.
You can set conditions to get specific articles or decide the order of the articles. For the purpose of this guide, we are using the following parameters:
If you've set the correct parameters, you will get a preview of the items being selected with the query.
Click Submit.
You will see a similar code snippet added to your template:
The above code will output a list of all the Article Items as links using the name.
We will modify the template a little, to add more information about the articles.
Replace the HTML
in the foreach loop with this snippet:
Remove the <ul>
tags surrounding the foreach loop.
Click Save.
To update the Articles Item template, follow these steps:
Go to Settings.
Expand the Templates folder in the Templating section.
Open the Articles Item template.
Select Master in the Master template:No master field.
Click Choose.
Click Save.
Open the Custom Umbraco Template folder.
Copy the contents of Blogpost.html.
Paste the content into Articles Item below the closing curly brace "}".
Remove everything from the <html>
(around line 8) to the end of the </div>
tag (around line 43) which is the header
and navigation
of the site since it is already mentioned in the Master template.
Remove everything from the <!-- Footer -->
tag (around line 113) to the end of the </html>
tag (around line 160)
Replace the static text within the <h1>
tags (around line 13) with the Model.Value reference to articleTitle.
Replace the static text within the <div>
tags (from line 25 to 39) with the Model.Value reference to articleContent.
Click Submit.
Click Save.
Check your browser, you should now see something similar to the screen below.