Copied to clipboard

Flag this post as spam?

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


  • Asger 25 posts 171 karma points
    Jun 24, 2016 @ 07:54
    Asger
    0

    Creating, calling and working with item-objects in Umbraco

    Hi Umbraco Forum.

    I am currently getting to know the umbraco cms, where i used to work with wordpress and joomla.

    I need to figure out the best way to create and work with item-objects in umbraco. Meaning that i want to enable my user to create content (ex. news/staff objects) that are not published as regular content. Then i wish to generate my page based on the content from the objects of news for example.

    I tried looking into this article: http://24days.in/umbraco/2015/strongly-typed-vs-dynamic-content-access/

    However, i cant seem to find the prefered way to do this.

    I hope someone can help.

    Best regards.

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Jun 24, 2016 @ 08:22
    Michaël Vanbrabandt
    0

    Hi asger,

    if I understand it you mean you want to create nodes in your content section that don't have a template ( and so don't have a specific url to display it ), correct?

    What I always do in my projects is creating a new root node called Content Elements.

    Step 1:

    Under settings go to document types and create a new Document Type without template. Allow this type at root so you can add this as a root node in your content section.

    Then you can create a child node for example News.

    Step 2:

    Under settings create a new Document Type without template called News Repository. Allow this as a child of your Content Elements document type.

    Now we can create news items.

    Step 3:

    Under settings create a new Document Type without template called News Item. Allow this as a child of your News Repository document type.

    Now you can fill up your content with some news. You can do this the same for your Staff and other elements that are just objects without templates.

    If you want for example display the latest 3 news items on your home page, you can create a partial view that renders this.

    Step 4:

    Under settings > partial views add a new partial view ( empty ) called RenderLatestNews

    Then you can do something like:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
    
        // Get the content root node using his alias
        var ucContentElements = Umbraco.ContentAtRoot().DescendantsOrSelf("ucContentElements").FirstOrDefault();
    
        // Get the news repo
        var ucNewsRepo = ucContentElements.FirstChild("ucNewsRepository");
    
        // Get the news items ( last 3 )
        var ucCourseItem = ucNewsRepo.Children("ucNews").Where("Visible").OrderBy("CreateDate descending").Take(3);
    
    }
    <div id="news">
        @foreach (var _newsItem in ucCourseItem)
        {
    
            <div class="item">
    
            </div>
    
        }
    </div>
    

    Step 5 :

    Load this partial view in your home page using:

    @Html.Partial("RenderLatestNews")

    Hope this make sense

    /Michaël

  • Magnus Szatkowski 28 posts 149 karma points
    Jun 27, 2016 @ 09:29
    Magnus Szatkowski
    0

    Hey Michaël,

    I am working with Asger on this project, and i am too new to Umbraco.

    What you have showed us here seems to work fine, however, I can't seem to call the values of our news items.

    What we have is news called "nyhed" (under "nyheder") which we dynamically creates. These news have different properties, which we wish to call and publish in a list. (eg. a date, the content and a link)

    Our current partial view is like this

        @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        // Get the content root node using his alias
        var news = Umbraco.ContentAtRoot().DescendantsOrSelf("nyheder").FirstOrDefault();
    
        // Get the news items ( last 3 )
        var ucCourseItem = news.Children("nyhed").Where("Visible").OrderBy("CreateDate descending").Take(2);
    
        }
    <div id="news">
    
    }
        <ul>
        @foreach (var _newsItem in ucCourseItem)
        { 
    
            <li>
               <div class="fnt-date">
                  <div>
                      <h3><!-- Here i need only the the day --></h3>
                  </div>
                  <div class="">
                       <p><!-- Here i need only the month --> </p> 
                  </div>
                </div>
                     <div class="fnt-content" data-link="#">
                        <!-- Here i need the content of the news (a string called "nyheden") -->
                     </div>
    
           </li>
    
        }
        </ul>
    </div>
    

    Do you know how I can get the content of the individual news items into the for each loop?

    Thank you so much for your help!

    Kind regards, Magnus

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Jun 27, 2016 @ 09:47
    Michaël Vanbrabandt
    0

    Hi Magnus,

    you can simply do _newsItem.PropertyAlias so for your properties it would be _newsItem.Date, _newsItem.Content, _newsItem.Link

    /Michaël

  • Magnus Szatkowski 28 posts 149 karma points
    Jun 27, 2016 @ 10:53
    Magnus Szatkowski
    0

    Thank you so much, This helped a lot :)

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Jun 27, 2016 @ 10:58
    Michaël Vanbrabandt
    0

    No problem, glad that I could help you out!

    /Michaël

  • Magnus Szatkowski 28 posts 149 karma points
    Jun 27, 2016 @ 11:44
    Magnus Szatkowski
    0

    I have one more question :D

    If i want to only create a list of newsItems which has a booloean == True called hoererTilTilbudTilSkoler, how do i do that?

    I have tried some different ways to do it but can't seem to get it right.

    it would be something like

    if (_newsItem.hoererTilTilbudTilSkoler == "True") { //i want to display a list of these items }
    

    Do you have a better way to call my objects boolean value and show a list of only the objects which has this value set to True ?

    Kind regards, Magnus

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Jun 27, 2016 @ 12:39
    Michaël Vanbrabandt
    0

    If its a boolean you can just do:

    if (_newsItem.hoererTilTilbudTilSkoler)
    {
        //do something else...
    }
    

    /Michaël

Please Sign in or register to post replies

Write your reply to:

Draft