Copied to clipboard

Flag this post as spam?

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


  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Feb 10, 2015 @ 14:29
    Michaël Vanbrabandt
    0

    Umbraco 7 create Child only nodes

    Hi,

    I have following Node structure:

    Home
    |
    |--Contact
    |
    |--Projects
        |
        |--Project 1
        |
        |--Project 2
    |
    |--Testimonials
        |
        |--Testimonial 1
        |
        |--Testimonial 2
    

    Now the node Testimonials and his child nodes are accessibel through the browser. How can I prevent this and only allow the Testimonial childs to be accessibel in other template nodes? I what to display them on the home page using a macro ( partial view ).

    /Michael

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 10, 2015 @ 14:52
    Jan Skovgaard
    100

    Hi Michaël

    Is testomonial just a content element? (Not a page) - If so, if it does not have a templated assigned it should not be possible to browse to the node since it won't be given any url (at least it has been working like that for a couple of minor versions ago).

    However...if it's just content elements then I think you should really consider creating an "Element repository" at the root level of your content section (Same level as your homepage) where you can create folders for different kind of content elements, which you can then refer to by using either a content picker or a multinode picker on a content page. That way you're keeping pages and elements seperate and those elements won't be browsable since you don't add a hostname to the section.

    It's a very common approach when building Umbraco sites, and other CMS sites.

    So in your case I would suggest that you create 3 document types in your settings section.

    1: "Content Elements" - This should be allowed to be created at the root level. Once it's created remove the checkbox from "allowed at root" on the document type. You only want one content element root.

    2: Create a "Testomonials folder" document type and allow it to be created under "Content Elements"

    3: Create a "Testomonial" document type and allow it to be created under "Testomonials folder"

    This way you can have different testomonial folders if the need should arise and you have a place where you can add other folders and content elements if the need should arise without cluttering up the tree mixing pages and elements.

    In your case you should be able to just create the "Content elements" root and then move your already created testomonial document structure down there.

    I hope this makes sense and is useful :)

    /Jan

  • Alex Skrypnyk 6148 posts 24077 karma points MVP 8x admin c-trib
    Feb 10, 2015 @ 14:52
    Alex Skrypnyk
    0

    Hi Michael,

    Very simple way to prevent access via browser at folder node, is add redirect at this node. It isn't perfect solution but very simple.

    Thanks

  • Herman 20 posts 141 karma points
    Feb 10, 2015 @ 14:58
    Herman
    0

    Try this: Add this to your home template:

    @{Html.RenderPartial("Testimonial/_Testimonial");}
    

    Create a partialview /Views/Shared/Testimonial/_Testimonial.cshtml

    And add this code to the partialview:

    @inherits UmbracoTemplatePage
    
    @{
        var home = Model.Content.AncestorOrSelf(1);
        var testimonialPage = home.Children.SingleOrDefault(x => x.DocumentTypeAlias == "--- Testamonials --- Change this!");
    }
    
    @if (testimonialPage != null)
    {
        foreach (var testimonial in testimonialPage.Children)
        {
            @testimonial.Name
        }
    }
    

    And --- Testamonials --- Change this! = your testimonial documenttypealias

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Feb 10, 2015 @ 15:12
    Michaël Vanbrabandt
    0

    Hi all,

    thanks for the replies. I will give you some more info about my Document Types. This is the current structure:

    Master
    |
    |--Contact
    |
    |--Projects
    |
    |--ProjectsItem
    |
    |--Testimonials
    |
    |--TestimonialsItem
    

    Every documenty type is a page so it has a template. Is it enough to just remove the template link from the testimonials?

    Creating the partial view ( macro ) is done so this is not a problem, it is only the accessability of the testimonials I would like to avoid.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 10, 2015 @ 16:49
    Jan Skovgaard
    0

    Hi Michaël

    If I remember correctly then yes - It's pretty easy to try out. Just remove the template and then you probably need to publish the testimonials branch. After doing that browse the "property" tab of the node and see if it has a url assigned. If not then you should not be able to browse the page. If it does not work you can always add the template to the document type again.

    But as I mentioned above...if the only purpose of the testimonials is to contain data to be used on other pages then consider making a content elements section where you can keep them :)

    Hope this helps.

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft