Articles and Article Items
Having an Articles Parent page, and a number of associated child articles, provides a good example of Umbraco's features. We'll assume our fictional company, Widgets Ltd, writes about ten articles a month and want the articles page to act like a blog. You could use this functionality for news, event pages, or any other collection of Document Types.
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.
Select ... next to the Document Types in the Settings tree.
Click Document Type with Template.
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.
Select ... next to the Document Types in the Settings tree.
Click Document Type with Template.
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 update Articles Main Document Type permissions:
Navigate to the Home Page Document Type and go to the Permissions tab.
Select Add child in the Allowed child node types. The Choose child node window opens.
Select Articles Main and click Save.
Navigate to the Articles Main Document Type and go to the List View tab.
Toggle Enable List view and click Save.
Enabling List View
To update Articles Item Document Type permissions:
Navigate to the Articles Main Document Type and go to the Permissions tab.
Select Add child in the Allowed child node types. The Choose child node window opens.
Select Articles Item and click Save.
Creating the Content Node
To add a content node:
Go to Content.
Select ... next to the HomePage and select Articles Main.
Enter the name for the article. We are going to call it Articles.
Enter the Article Title, Article Content, and click Save and Publish. When you click on Save and Publish, you will notice an empty list view is created.
We still need to add the child nodes which will be displayed in the list view making it easier to view them. You can create new nodes from this section.
If you do not see the list view, try refreshing the page.
Click Create Articles Item to add two child nodes called Article 1, Article 2, and click Save and Publish.
![](https://docs.umbraco.com/~gitbook/image?url=https%3A%2F%2F65787334-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F8h0xdoteqcFVV1pGZgk0%252Fuploads%252Fgit-blob-885dfd4e5a81228678eb6afa99a8efe0ac50720b%252Ffigure-40-articles-created-v8.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=e37c5332&sv=1)
Updating the Template
To update the Articles Item template, follow these steps:
Go to Settings.
Expand the Templates folder in the Templating section. You should see a template titled Articles Main.
Select Master in the Master template and click Save.
Open the Custom Umbraco Template folder.
Copy the contents of Blog.html and paste the content into Articles Main below the closing curly brace "}".
Take care when pasting the template not to overwrite the first line
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ContentModels.ArticlesMain>
. If you get an error when loading the page ensure the last part in <> brackets matches your Document Type alias.
Remove everything from the
<html>
(around line 9) to the end of the</div>
tag (around line 44) which is theheader
andnavigation
of the site since it is already mentioned in the master template.Remove everything from the
<!-- Footer -->
tag (around line 84) to the end of the</html>
tag (around line 131)Replace the static text within the
<h1>
tags (around line 13) with the Model.Value reference to articlesTitle.Replace the static text within the
<div>
tags (from line 24 to 30) with the Model.Value reference to articlesBodyText.Articles Main Template Define a query for all articles below the
<h3>
tag (around line 32) 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'll use 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, and you will see a code snippet has been added to your template. It will look similar to this:
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:Click Save.
To update the Articles Item template, follow these steps:
Go to Settings.
Expand the Templates folder in the Templating section. You should see a template titled Articles Item.
Select Master in the Master template and click Save.
Open the Custom Umbraco Template folder.
Copy the contents of Blogpost.html and paste the content into Articles Item below the closing curly brace "}".
Take care when pasting the template not to overwrite the first line
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ContentModels.ArticlesItem>
. If you get an error when loading the page ensure the last part in <> brackets matches your Document Type alias.
Remove everything from the
<html>
(around line 9) to the end of the</div>
tag (around line 44) which is theheader
andnavigation
of the site since it is already mentioned in the master template.Remove everything from the
<!-- Footer -->
tag (around line 114) to the end of the</html>
tag (around line 161)Replace the static text within the
<h1>
tags (around line 14) with the Model.Value reference to articleTitle.Replace the static text within the
<div>
tags (from line 26 to 41) with the Model.Value reference to articleContent.Articles Item Template 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%2F65787334-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F8h0xdoteqcFVV1pGZgk0%252Fuploads%252Fgit-blob-81aad66d64207c939c424ece692c16317f62d0bd%252Farticle-main-frontend.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=f5b3fa4c&sv=1)
Last updated