Articles and Article Items
Last updated
Last updated
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.
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.
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 |
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.
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 |
Click Save
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.
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.
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.
5. Click **Create Articles Item** to add two child nodes called **Article 1**, **Article 2**, and click **Save and Publish**.
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 the header
and navigation
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.
Define a query for all articles below the <h3>
tag (around line 32) 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'll use 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, 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 the header
and navigation
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.
Click Save.
Check your browser, you should now see something similar to the screen below.