Copied to clipboard

Flag this post as spam?

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


  • Johan 188 posts 380 karma points
    Oct 19, 2011 @ 18:20
    Johan
    0

    Loop out uComp multinode picker links with dynamic alias

    Want to do something like this:

    @using umbraco.MacroEngines;
    
    @{
    var columnToList = @Parameter.columnToList;
    // columnToList is the alias of my multiple content node picker
    // footerLinksColumn1 in this case
    }
    <ul>
        @foreach (var x in @Model.AncestorOrSelf().@columnToList) {
            <li>Loop out the link here</li>
        }
    </ul>

    And the XML output from umbraco.config looks like this:

     

        <footerLinksColumn1>
          <MultiNodePicker>
            <nodeId>1089</nodeId>
            <nodeId>1090</nodeId>
            <nodeId>1068</nodeId>
            <nodeId>1064</nodeId>
            <nodeId>1070</nodeId>
            <nodeId>1074</nodeId>
            <nodeId>1138</nodeId>
            <nodeId>1071</nodeId>
          </MultiNodePicker>
        </footerLinksColumn1>

     

  • Rich Green 2246 posts 4008 karma points
    Oct 19, 2011 @ 18:26
    Rich Green
    0

    Hi,

    This project has examples of razor & uComponents MNTP http://our.umbraco.org/projects/developer-tools/cultiv-razor-examples 

    Though I'm not sure if you're saying you don't know how to loop through the xml or to assign the columnToList?

    Rich

  • Rodion Novoselov 694 posts 859 karma points
    Oct 20, 2011 @ 00:36
    Rodion Novoselov
    0

    Hi. I suspect you want this:

    @{ var columnToList = Parameter.columnToList; }

    <ul>
      @foreach(var x in Model.AncestorsOrSelf().Select(columnToList)) {
         <li>@x</li>
      }
    </ul>
  • Johan 188 posts 380 karma points
    Oct 20, 2011 @ 16:00
    Johan
    0

    @Rich Green
    Thanks for the tip. Awesome package. My issue is however that i want to do this:

      @foreach (var x in Model.footerLinksColumn1) {
    var contentItem = Model.NodeById(nodeId.InnerText); <li>@contentItem.Name</li>
    }

    But want "footerLinksColumn1" to be a dynamic variable/parameter.

    @Rodion Novoselov
    Thanks, that is what i want but i still can't get it to work. It wont even parse the script :(

  • Rodion Novoselov 694 posts 859 karma points
    Oct 20, 2011 @ 22:41
    Rodion Novoselov
    0

    Johan, could you tell what version you use and what error it says when parsing the script? I've just tried it on my local test installation it and it looks ok. Perhaps your installation misses some dll files or configuration.

  • Johan 188 posts 380 karma points
    Oct 21, 2011 @ 12:10
    Johan
    0

    If i use your exact code i get the following output:

    <ul>
            <li>umbraco.MacroEngines.DynamicXml</li>
    </ul>

    I'm using umbraco 4.7.1. Should i maybe add .MultiNodePicker.nodeId to the end of Model.AncestorsOrSelf().Select(columnToList) ?

  • Rodion Novoselov 694 posts 859 karma points
    Oct 21, 2011 @ 12:26
    Rodion Novoselov
    0

    Ok. And what is the 'columnToList' parameter in your macro settings? (I mean what type does it have etc?)

  • Johan 188 posts 380 karma points
    Oct 21, 2011 @ 12:52
    Johan
    0

    It is "footerLinksColumn1" in this case. It is just a variable with the name of the alias of the multiNodePicker I'm using. So that i can use the script on many places.

    Edit: Oh, and the property type is propertyTypePicker wich i guess is just a string 'cause it outputs "footerLinksColumn1". And if i muanually type "footerLinksColumn1" instead of using the variable in the Select i get the same result as with the variable.

  • Rodion Novoselov 694 posts 859 karma points
    Oct 22, 2011 @ 19:57
    Rodion Novoselov
    0

    How about this:


    @{
      var ids = Parameter.yourPicker.Split(",");
      var prop = Parameter.propertyName;
    }

    <ul>
      @foreach(var id in ids) {
       var node = Library.NodeById(id);            
       <li>
         @node.GetProperty(prop)
       </li>
      }
    </ul>
  • Johan 188 posts 380 karma points
    Oct 24, 2011 @ 13:25
    Johan
    0

    I don't think those are the droids I'm looking for. I think the problem with that solutions is that "yourPicker" is "propertyName" in this case and the dynamic part becomes a problem again :/.

  • Rodion Novoselov 694 posts 859 karma points
    Oct 24, 2011 @ 14:05
    Rodion Novoselov
    0

    Well, if you want to get a parameter value by the name of parameter represented by a string you can make use of the fact that the actual type of the Parameter property (despite that formally it returns a dynamic value) is 'IParameterDictionary' (you can make sure of it e.g. by the sources) so the following should work I suppose:

    var parameterValue = ((IParameterDictionary)Parameter)[parameterName];

     

Please Sign in or register to post replies

Write your reply to:

Draft