Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • arash 3 posts 23 karma points
    Mar 22, 2014 @ 13:47
    arash
    0

    master detail in template

    hello I am new to umbraco , I have created a document type with two field header and body , the scenario is to be show header as link and when user click it , see text , some think like news header and then text.(master -detail) how can I implement this ? I prefer razor since I am c# developer but any comment is appreciated.

    thanks.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 22, 2014 @ 15:30
    Dennis Aaen
    2

    Hi Arash,

    Since you´re new to Umbraco I will recommend you to see these video´s on Umbraco TV if you don´t have seen them yet. This will explain the basic principles working with the Umbraco CMS.

    http://umbraco.tv/videos/umbraco-v7/implementor/fundamentals/

    But if I should try to help you I would make a Master document type that contains all the common fields for each page it could be header body text, and navigation title some SEO stuff and so on. When you have created this document type be sure that you also creates matching template,it will be done automatically unless you removed the tick.

    In your master template you will place all the common markup for all your pages. A master template could look like this in it´s simple form:

    @inherits UmbracoTemplatePage

    @{
        Layout = null;
    }<!DOCTYPE html>

    <html>
    <head>
        <title></title>
    </head>
    <body >
       
        @RenderBody()

    </body>
    </html>

    Take a look at this video make it make sense then; http://umbraco.tv/videos/umbraco-v7/implementor/fundamentals/templating/advanced-master-templates/

    You need to create document types for all of your different page types, for in your case you need to make a document type e.g called newsList and a document type e.g newsItem.

    Both of these documen type need to have a template and remember to inhert from master (See the video) Add the properties you want the user to fill out on the newsList and the NewsItem. In your case heading and bodyText.

    To get data out of Umbraco you need to create a Razor file. Go to the developer selection, select the Partial View Macro files. Create a file and called it e.g NewsItemList, this is the file that gonna list all our news items,

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @* Ensure that the Current Page has children, where the property umbracoNaviHide is not True *@
    @if (CurrentPage.newsItems.Where("Visible").Any())
    {
        <ul>           
            @* For each child page under the root node, where the property umbracoNaviHide is not True *@
            @foreach (var newsItem in CurrentPage.newsItems.Where("Visible"))
            {
                <li>
                    <a href="@newsItem.Url">@newsItem.heading</a>
                </li>
            }
        </ul>
    }

    In the NewsItem template, located in the template folder under settings, you can output data in two different ways:

    First option is by creating a razor file and output the heading and the body text, and the place the macro on the newsItem template, To get the heading and body text out in razor for currenpage looks like, Then you can add your HTML markup around this.

    @CurrentPage.heading
    @CurrentPage.bodyText

    You can read more about @CurrentPage here: http://our.umbraco.org/documentation/Reference/Mvc/views#PropertiesavailableinViews

    The other one is by  using what Umbraco calls an Umbraco field.  And it will look like this:

    @Umbraco.Field("heading")
    @Umbraco.Field("bodyText")

    You can read more about the @Umbraco,Field here: http://our.umbraco.org/documentation/Reference/Mvc/views#RenderingafieldwithUmbracoHelper

    I you´re using the Umbraco backoffice there is a button for inserting Umbraco fields. I have made a screenshot where you can find the button for inserting umbraco fields:

    I hope this can helps you and make sense. But as I said in the beginning at my post with I would recommend you to see the free videos about the basic principles working with the Umbraco CMS to get them in place. I know it´s a lot of information.

    Agian you can see the videos here: http://umbraco.tv/videos/umbraco-v7/implementor/fundamentals/

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft