Copied to clipboard

Flag this post as spam?

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


  • Clare 37 posts 117 karma points
    Nov 08, 2013 @ 15:24
    Clare
    0

    Razor - multiple parameters for macro

    Following on from my previous post:
    http://our.umbraco.org/forum/developers/razor/46054-Razor-how-to-list-descendants-from-multiple-lists

    I now need to add an extra parameter but don't know how to format the code.

    I currently have a parameter for ProgrammeSchool which is working fine but I also need one for ProgrammeLevel.

    How would I amend the code below:

    @using umbraco.MacroEngines
    @inherits DynamicNodeContext
    @{
        string schoolToFind = Parameter.ProgrammeSchool;
        var root =Model.AncestorOrSelf(1);
        var programmeNames = root.DescendantsOrSelf("Programme").OrderBy("programmeName").ToList();
           
           <div>
            @foreach(var item in programmeNames)
            {
                 string[] school = item.school.ToString().Split(',');
               
                if (school.Contains(schoolToFind))
                    {
                        <li>
                        <a href="@item.Url">@item.programmeName - @item.qualificationType</a>
                        </li>
                        }
               
                             }
        </div>
               
    }
  • Mike 35 posts 100 karma points
    Nov 08, 2013 @ 15:30
    Mike
    0
        string schoolToFind =Parameter.ProgrammeSchool;
        string nextParm =Parameter.NextParm;
    string anotherParm =Parameter.AnotherParm;
    Don't forget to add the parameter to your macro as well.
  • Clare 37 posts 117 karma points
    Nov 08, 2013 @ 15:40
    Clare
    0

    Thanks Mike,

    I have added the parameter to my macro and added in the line as you suggest however I'm still not sure how to write the code for these lines so they inlcude the new parameter aswell:

     string[] school = item.school.ToString().Split(',');
               
                if (school.Contains(schoolToFind))

    This is my updated code:

    @using umbraco.MacroEngines
    @inherits DynamicNodeContext
    @{
        string schoolToFind = Parameter.ProgrammeSchool;
        string levelToFind = Parameter.ProgrammeLevel;
        var root =Model.AncestorOrSelf(1);
        var programmeNames = root.DescendantsOrSelf("Programme").OrderBy("programmeName").ToList();
           
           <div>
            @foreach(var item in programmeNames)
            {
                 string[] school = item.school.ToString().Split(',');
               
                if (school.Contains(schoolToFind))
                    {
                        <li>
                        <a href="@item.Url">@item.programmeName - @item.qualificationType</a>
                        </li>
                        }
               
                             }
        </div>
               
    }

  • Mike 35 posts 100 karma points
    Nov 08, 2013 @ 15:47
    Mike
    0

    Is the "level" within the document type? OR are you talking about a "level" on the content tree?

  • Clare 37 posts 117 karma points
    Nov 08, 2013 @ 15:51
    Clare
    0

    Yes 'level' is the alias for a property within the document type (sorry for confusion)

  • Mike 35 posts 100 karma points
    Nov 08, 2013 @ 16:12
    Mike
    100

    in your foreach loop:

    if (school.Contains(schoolToFind))

    chage to:

    if ((item.level == levelToFind) && (school.Contains(schoolToFind)))

  • Clare 37 posts 117 karma points
    Nov 08, 2013 @ 16:16
    Clare
    0

    Thanks Mike - perfect!

  • Clare 37 posts 117 karma points
    Nov 08, 2013 @ 16:16
    Clare
    0

    Thanks Mike - perfect!

Please Sign in or register to post replies

Write your reply to:

Draft