Articles and Article Items
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.
Creating Articles and Article Items
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:
Group Field Name Alias Data Type Intro
Articles Title
articlesTitle
Textstring
Intro
Articles Body Text
articlesBodyText
Rich Text Editor
Articles Main Document Type Data Properties 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:
Group Field Name Alias Data Type Content
Article Title
articleTitle
Textstring
Content
Article Content
articleContent
Rich Text Editor
Article Item Document Type Data Properties Click Save
Updating the Document Type Permissions
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.
Adding child Node Click Configure as a collection.
Select List View - Content.
Click Save.
Enabling Collection
Creating the Content Node
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.
Content Tree with Articles
Updating the Template
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 theheader
andnavigation
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.Articles Main Template Define a query for all articles below the
<h3>
tag (around line 30) of the<!-- Latest blog posts -->
section.Query Builder 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:
Query 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 theheader
andnavigation
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.Articles Item Template Click Submit.
Click Save.
Check your browser, you should now see something similar to the screen below.
![](https://docs.umbraco.com/~gitbook/image?url=https%3A%2F%2F3701346516-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FG1Byxw7XfiZAj8zDMCTD%252Fuploads%252Fgit-blob-46da0ea2da60d3f7ebfe997414d5ed67d56e35c4%252Farticle-main-frontend-v14.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=33c368fa&sv=1)
Last updated