Copied to clipboard

Flag this post as spam?

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


  • pikej 27 posts 47 karma points
    Jun 28, 2011 @ 22:01
    pikej
    0

    next and previous buttons

    hi guys,

    I am trying to do simple navigatin consisting of two links: next / previous and I am following razor code

     @foreach (var item in @Model.DescendantsOrSelf())

        {

      var linkN = @Model.Next().Url;

      var linkP = @Model.Previous().Url;

      <a href="@linkN">Next</a>

     <a href="@linkP">Previous</a> }

    it works fine but when there are no siblings and null is returned there is an error. how to avoid this?

    regards,

    pikej 

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Jun 29, 2011 @ 09:04
    Sebastiaan Janssen
    1

    You can do something like:

        @{
            if (@Model.Next() != null) {
                <a href="@Model.Next().Url">Next</a>
            }
            if (@Model.Previous() != null) {
                <a href="@Model.Previous().Url">Previous</a>
            }
        }
  • pikej 27 posts 47 karma points
    Jul 05, 2011 @ 10:06
    pikej
    0

    thanks a lot Sebastiaan, your code works very well!

  • Niklas Hjelm 104 posts 125 karma points
    Aug 08, 2011 @ 14:43
    Niklas Hjelm
    0

    Hi!

    This is a really good example. I have a question.

    I have a structure like this:

    • Photos
      Category1
      Image1 
      Image2

      Category2
      Image1
      Image2
    Is there a way to navigate images from the root even if they are in parent folders? With your example I can only get the sibling. 
    Thanks / Niklas
  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Aug 08, 2011 @ 14:46
  • Niklas Hjelm 104 posts 125 karma points
    Aug 08, 2011 @ 14:55
    Niklas Hjelm
    0

    Thanks I'll do that. BTW is there a way to get a specific document type using where? Like the example below but for document type.

    @foreach(var item in Model.Children.Where("bodyText.Contains(\"cat\")"))
    {
        @item.Name
    }

     

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Aug 08, 2011 @ 15:15
    Sebastiaan Janssen
    0

    Sure, just use: 

    Model.Children.Where("NodeTypeAlias == \"cat\"");
  • Steve 472 posts 1216 karma points
    Dec 18, 2015 @ 17:09
    Steve
    0

    I am trying to add previous and next buttons including only a specific nodeTypeAlias, but this isn't working. I get an error.

    <umbraco:Macro runat="server" language="cshtml">
    <div class="prevNextWrap">
         @{
        if (@Model.Next() != null) {
            <a class="prevNext" href="@Model.Next().Url">Next</a>
        }
        if (@Model.Previous() != null) && @Model.Where("NodeTypeAlias == \"TwoColumnAdmissionsLeftNav\"") {
            <a class="prevNext" href="@Model.Previous().Url">Previous</a>
        }
    }
    </div>
    

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies