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:

  1. Go to Settings.

  2. Click ... next to the Document Types in the Settings tree.

  3. Select Create....

  4. Select Document Type with Template.

  5. Enter a Name for the Document Type. Let's call it Articles Main.

  6. Let's add two fields with the following specifications:

    GroupField NameAliasData Type

    Intro

    Articles Title

    articlesTitle

    Textstring

    Intro

    Articles Body Text

    articlesBodyText

    Rich Text Editor

    Articles Main Document Type Data Properties
  7. Click Save

To create Articles Item Document Type, follow these steps:

  1. Go to Settings.

  2. Click ... next to the Document Types in the Settings tree.

  3. Select Create....

  4. Select Document Type with Template.

  5. Enter a Name for the Document Type. Let's call it Articles Item.

  6. Let's add two fields with the following specifications:

    GroupField NameAliasData Type

    Content

    Article Title

    articleTitle

    Textstring

    Content

    Article Content

    articleContent

    Rich Text Editor

    Article Item Document Type Data Properties
  7. Click Save

Updating the Document Type Permissions

To add Articles Main as a child node:

  1. Navigate to the Home Page Document Type.

  2. Go to the Structure tab.

  3. Select Choose in the Allowed child node types.

  4. Select Articles Main.

  5. Click Choose.

  6. Click Save.

To update Articles Main Document Type permissions:

  1. Navigate to the Articles Main Document Type.

  2. Go to the Structure tab.

  3. Select Choose in the Allowed child node types.

  4. Select Articles Item.

  5. Click Choose.

    Adding child Node
  6. Click Configure as a collection.

  7. Select List View - Content.

  8. Click Save.

    Enabling List View

Creating the Content Node

To add a content node:

  1. Go to Content.

  2. Select ... next to the HomePage node.

  3. Click Create.

  4. Select Articles Main.

  5. Enter the name for the article. We are going to call it Articles.

  6. Enter the content in the Article Title and Article Body Text fields.

  7. 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.

  8. Click Create Articles Item.

  9. Enter the name for the article. We are going to call it Article 1.

  10. Enter the content in the Article Title and Article Content fields.

  11. Repeat steps 8 to 10 to create Article 2.

  12. Click Save and Publish.

    Content Tree with Articles

Updating the Template

To update the Articles Item template, follow these steps:

  1. Go to Settings.

  2. Expand the Templates folder in the Templating section.

  3. Open the Articles Main template.

  4. Select Master in the Master template:No Master field.

  5. Click Choose.

  6. Click Save.

  7. Open the Custom Umbraco Template folder.

  8. Copy the contents of Blog.html.

  9. Paste the content into Articles Main below the closing curly brace "}".

  10. 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.

  11. Remove everything from the <!-- Footer --> tag (around line 83) to the end of the </html> tag (around line 130)

  12. Replace the static text within the <h1> tags (around line 12) with the Model.Value reference to articlesTitle.

  13. Replace the static text within the <div> tags (from line 23 to 29) with the Model.Value reference to articlesBodyText.

    Articles Main Template
  14. Define a query for all articles below the <h3> tag (around line 30) of the <!-- Latest blog posts --> section.

    Query Builder
  15. 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
  16. If you've set the correct parameters, you will get a preview of the items being selected with the query.

  17. Click Submit.

  18. You will see a similar code snippet added to your template:

@{ var selection = Umbraco.Content(Guid.Parse("56aa9cc5-243b-4947-8fb1-37b209b97373")) .ChildrenOfType("articlesItem") .Where(x => x.IsVisible()) .OrderByDescending(x => x.CreateDate); }

```

  1. The above code will output a list of all the Article Items as links using the name.

  2. We will modify the template a little, to add more information about the articles.

  3. Replace the HTML in the foreach loop with this snippet:

    <article class="special">
        <div class="articledate" > @item.CreateDate </div>
        <div class="articletitle"><a href="@item.Url()">@item.Name()</a></div>
        <div class="articlepreview">@Html.Truncate(item.Value("articleContent").ToString(), 20, true)<a href="@item.Url()">Read More..</a></div>
    </article>
  4. Click Save.

To update the Articles Item template, follow these steps:

  1. Go to Settings.

  2. Expand the Templates folder in the Templating section.

  3. Open the Articles Item template.

  4. Select Master in the Master template:No master field.

  5. Click Choose.

  6. Click Save.

  7. Open the Custom Umbraco Template folder.

  8. Copy the contents of Blogpost.html.

  9. Paste the content into Articles Item below the closing curly brace "}".

  10. 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.

  11. Remove everything from the <!-- Footer --> tag (around line 113) to the end of the </html> tag (around line 160)

  12. Replace the static text within the <h1> tags (around line 13) with the Model.Value reference to articleTitle.

  13. Replace the static text within the <div> tags (from line 25 to 39) with the Model.Value reference to articleContent.

    Articles Item Template
  14. Click Save.

Check your browser, you should now see something similar to the screen below.

Finished Articles section

Last updated