Copied to clipboard

Flag this post as spam?

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


  • Brad Ford 34 posts 75 karma points
    Jul 17, 2013 @ 08:25
    Brad Ford
    0

    Best way to structure this data?

     

    I am building a site for a collection of books.

    I'm not sure however how to structure my data and hope someone here can set me straight. 

    This is what I have currently. 

    THE BOOKS appears on the top nav of the site as a clickable link which currently links a page called the-books.aspx that goes currently to an empty page. 

    THE BOOKS datatype can have BOOK as a child. 

    However, I want THE BOOKS page to redirect to one of the BOOK pages. Either one that is manually set, or one that is the most recently approve etc.. 

    My thought is I'd need some sort of macro in THE BOOKS page that loops around the child pages and find the right one to redirect to. 

    Is this the correct approach to this task? 

    And while I am at it, what would the razor look like that loops over the child BOOK elements, and how could that trigger a page redirect. 

    Am I approaching this correctly? 

     

     

     

     

     

     

     

  • Brad Ford 34 posts 75 karma points
    Jul 17, 2013 @ 08:48
    Brad Ford
    0

    I tried to create a macro that looks for a child page with a bit set that I called IsCurrentBook. 

    That macro looks like this. 

     

    The macro saves just fine. I put it in THE BOOKS page and NOTHING gets output from it. Not the text In the Macro, nor the 'Here' text in the else statement. 

     

  • Justin Moser 20 posts 92 karma points
    Jul 17, 2013 @ 17:19
    Justin Moser
    100

    Have you tried the umbracoInternalRedirectId property?

    Put a content picker on 'THE BOOKS' node document type with that alias and then choose the book you want to redirect that page to.

    Then there'll be no need for the macro, its a built in property so will automatically redirect without you needing to write any code to handle it.

    I use it on my Root node to redirect to the home node.

    http://our.umbraco.org/wiki/reference/umbraco-best-practices/umbracointernalredirectid

     

    Hope that helps.

  • Justin Moser 20 posts 92 karma points
    Jul 17, 2013 @ 17:31
    Justin Moser
    0

    but if you really want to use the method you originally posted then in the navigation code, for that item "THE BOOKS" why dont you loop through its children, find the child with the property of "IsCurrentBook" set to true, then render a simple link? How are you building the navigation? Are you iterating through the content tree? If so, try:

     

    @foreach(var node in Model.AncestorsOrSelf().FirstOrDefault().Children) // replace this loop for whatever you're using

    {

    if(node.NodeTypeAlias == "THEBOOKS")

       {

    var currentBook = node.Children.Where("IsCurrentBook").FirstOrDefault();

    <a [email protected]">THE BOOKS</a>

       }

    }

     

    Also, just as a side not, if you're ever inside an if statement and checking a bool value, you dont need to do "foo == true", you just need to do if (foo).

    Hope either of these help solve your issue.

  • Brad Ford 34 posts 75 karma points
    Jul 18, 2013 @ 01:02
    Brad Ford
    0

    Thanks Justin. THE BOOKS page now as a simple Content Picker were they can pick which book page becomes the default when you click THE BOOKS link. 

Please Sign in or register to post replies

Write your reply to:

Draft