Copied to clipboard

Flag this post as spam?

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


  • Dominic Kelly 114 posts 133 karma points
    Jan 16, 2012 @ 17:11
    Dominic Kelly
    0

    Content Picker in Ultimate Picker?

    So I have an Ultimate Picker which lets me select nodes based on a Data Type which has a Media Picker and a Content Picker.

    @foreach (var nodeId in @Model.intermalPromotions)
    {
    @nodeId;
    }

    Returns a comma seperated list of nodes. From here I need to be able to create an image based on the media picker and a link based on a content picker.

    As documentation is so slim on the ground can someone please help?

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 16, 2012 @ 17:43
    Tom Fulton
    0

    Hi,

    You probably need to split the comma separated list and loop through each node, then use Library.NodeById to get the referenced node.  Then you can access it's properties from that.  Something like this:

      string[] nodes = @Model.internalPromotions.Split(',');
     
      foreach (string nodeId in nodes)
      {
       var curNode = Library.NodeById(nodeId);
      
       if (curNode.HasProperty("yourMediaPickerAlias"))
       {
         var media = Library.MediaById(curNode.yourMediaPickerAlias);
         <img src="@media.umbracoFile" />
       }

       if (curNode.HasProperty("yourContentPickerAlias"))
       {
        var content = Library.NodeById(curNode.yourContentPickerAlias);
        <a href="@content.Url">@content.Name</a>
       }
      }

    Hope this helps,
    Tom

  • Dominic Kelly 114 posts 133 karma points
    Jan 16, 2012 @ 17:49
    Dominic Kelly
    0

    Thanks a lot for the reply. The syntax is not something I'm familiar with at all! I've pasted in:

     

     

      string[] nodes = @Model.internalPromotions.Split(',');

     

      foreach (string nodeId in nodes)

     

      {

     

       var curNode = Library.NodeById(nodeId);

     

       if (curNode.HasProperty("internalPromotionBackground"))

     

       {

     

         var media = Library.MediaById(curNode.internalPromotionBackground);

     

         <imgsrc="@media.umbracoFile"/>

     

       }

     

       if (curNode.HasProperty("internalPromotionLink"))

     

       {

     

        var content = Library.NodeById(curNode.internalPromotionLink);

     

        <a href="@content.Url">@content.Name</a>

     

       }

     

      }
     

    But I get this error 'Error loading MacroEngine script (file: InternalPromotions.cshtml)'

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 16, 2012 @ 17:53
    Tom Fulton
    0

    Hi,

    Does it give you any additional error info?  You might be able to get more info by adding ?umbdebugshowtrace=1 to your querystring and checking the trace logs at the bottom for any errors.

    Also it will fail if the current page doesn't have internalPromotions set, but you can fix that by wrapping in a check (see below).

      if(@Model.HasProperty("internalPromotions"))
     
    {
       
    string[] nodes =@Model.internalPromotions.Split(',');
     
       
    foreach(string nodeId in nodes)
       
    {
         
    var curNode =Library.NodeById(nodeId);
         
         
    if(curNode.HasProperty("yourMediaPickerAlias"))
         
    {
           
    var media =Library.MediaById(curNode.yourMediaPickerAlias);
           
    <img src="@media.umbracoFile"/>
         
    }
     
         
    if(curNode.HasProperty("yourContentPickerAlias"))
         
    {
         
    var content =Library.NodeById(curNode.yourContentPickerAlias);
         
    <a href="@content.Url">@content.Name</a>
         
    }
     
       
    }
       
    }

    -Tom

  • Dominic Kelly 114 posts 133 karma points
    Jan 16, 2012 @ 18:02
    Dominic Kelly
    0

    No sadly absolutely no errors whatsoever other than the meaningless output I gave. 

    I have a Document Type with an alias of 'internalPromotion'. This has two properties 'internalPromotionBackground' (Type Media Picker) and 'internalPromotionLink' (Type Content Picker).

    I'm able to select the related content in the backoffice, but can't figure out the Macro.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 16, 2012 @ 18:06
    Tom Fulton
    0

    Try checking your web.config - maybe you have DebugMode disabled which will hide the "real" errors.  Check that this key is set to true:

    <add key="umbracoDebugMode" value="false" />

    Also did you try appending the ?umbdebugshowtrace=1 to see if you get a better error?

    -Tom

  • Dominic Kelly 114 posts 133 karma points
    Jan 16, 2012 @ 18:06
    Dominic Kelly
    0

    <add key="umbracoDebugMode" value="true" />

  • Dominic Kelly 114 posts 133 karma points
    Jan 16, 2012 @ 18:07
    Dominic Kelly
    0

    ?umbdebugshowtrace=1 seems to do something...

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 16, 2012 @ 18:08
    Tom Fulton
    0

    Scroll down and look for any text in red, you should find something like Error Loading Razor Script, that hopefully has a "real" error message in it

  • Dominic Kelly 114 posts 133 karma points
    Jan 16, 2012 @ 18:11
    Dominic Kelly
    0

    Actually the get parameter just broke my existing javascript. The error message is

     

    <div title="Macro Tag: 'InternalPromotions'" style="border: 1px solid #009;">Error loading MacroEngine script (file: InternalPromotions.cshtml)</div>

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 16, 2012 @ 18:15
    Tom Fulton
    0

    What about if you scroll down under "Trace Information" - any errors there?

    What version of Umbraco are you using?

    Also just a thought, maybe try this instead, perhaps there is some casting going on with that datatype:

      if (@Model.HasProperty("internalPromotions"))
      {
        string[] nodes = @Model.GetPropertyValue("internalPromotions").Split(',');
     
        foreach (string nodeId in nodes)
        {
         var curNode = Library.NodeById(nodeId);
        
         if (curNode.HasProperty("yourMediaPickerAlias"))
         {
           var media = Library.MediaById(curNode.yourMediaPickerAlias);
           <img src="@media.umbracoFile" />
         }
     
         if (curNode.HasProperty("yourContentPickerAlias"))
         {
          var content = Library.NodeById(curNode.yourContentPickerAlias);
          <a href="@content.Url">@content.Name</a>
         }
     
        }
       }
  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 16, 2012 @ 18:16
    Tom Fulton
    0

    Make sure you are wrapping the above in @{ } also...ex:

    @{
      if (@Model.HasProperty("internalPromotions"))
      {
        string[] nodes = @Model.GetPropertyValue("internalPromotions").Split(',');
     
        foreach (string nodeId in nodes)
        {
         var curNode = Library.NodeById(nodeId);
        
         if (curNode.HasProperty("yourMediaPickerAlias"))
         {
           var media = Library.MediaById(curNode.yourMediaPickerAlias);
           <img src="@media.umbracoFile" />
         }
     
         if (curNode.HasProperty("yourContentPickerAlias"))
         {
          var content = Library.NodeById(curNode.yourContentPickerAlias);
          <a href="@content.Url">@content.Name</a>
         }
     
        }
       }
      }
  • Dominic Kelly 114 posts 133 karma points
    Jan 16, 2012 @ 18:18
    Dominic Kelly
    0

     @{

       <divclass="one"></div>

       if (@Model.HasProperty("internalPromotions"))

       {

       <divclass="two"></div>

       }

    }

     

    Outputs div one, but not div two?

     

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 16, 2012 @ 18:20
    Tom Fulton
    0

    That means the current page doesn't have a property called "internalPromotions" - have you double checked?  Also I noticed in your first example you used intermalPromotions - is there a typo maybe?

  • Dominic Kelly 114 posts 133 karma points
    Jan 16, 2012 @ 18:23
    Dominic Kelly
    0

    Weird. Ok I've double checked and fixed the typo:

    http://screencast.com/t/XRUxVfeIiB

    @{

       <divclass="one">one</div>

        if (@Model.HasProperty("internalPromotions"))

       {

       <divclass="two">two</div>

       }

    }

    I've also republished everything.

    one and two is now output, which is a start!

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 16, 2012 @ 18:25
    Tom Fulton
    0

    Maybe you can start removing things line by line to see if you can determine where the error is.  I don't know why you aren't getting better error messages.  On 4.7.1 you should get good errors unless umbracoDebugMode is turned off (at least in my experience)

  • Dominic Kelly 114 posts 133 karma points
    Jan 16, 2012 @ 18:30
    Dominic Kelly
    0

    @{

       if (@Model.HasProperty("internalPromotions"))

       {

        string[] nodes = @Model.GetPropertyValue("internalPromotions").Split(',');

        foreach (string nodeId in nodes)

        {

        var curNode = Library.NodeById(nodeId);

        <div class="two">s @curNode</div>

        }

       }

    }

    Ok a bit further... @curNode appears to be empty? The 3 divs are returned correctly but only contain the prefix 's'.   

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 16, 2012 @ 18:38
    Tom Fulton
    0

    Try outputting the value of nodeId, it should be one of the IDs in your internalPromotions list.  Also you can output the internalPromotions to make sure it's set...

    <p>Internal Promotions:  @Model.GetPropertyValue("internalPromotions")</p>

    in your loop:

    <p>current node id:  @nodeId</p>

    Also I don't think you can just output the node, try @curNode.Name instead

    -Tom

  • Dominic Kelly 114 posts 133 karma points
    Jan 16, 2012 @ 18:42
    Dominic Kelly
    0
    Internal Promotions:  @Model.GetPropertyValue("internalPromotions")
    Correctly outputs the ids at the top of the macro.
    current node id:  @nodeId
    Correctly outputs the ids within the loop.
    @curNode.Name

    In the loop is empty!

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 16, 2012 @ 18:45
    Tom Fulton
    0

    What version of umbraco are you using?

    Also are you sure that all of the node IDs listed in your tests are published?  I think Ultimate Picker can work with unpublished data but Razor can only access published data.

  • Dominic Kelly 114 posts 133 karma points
    Jan 16, 2012 @ 18:54
    Dominic Kelly
    0

    v4.7.1.1 yup everything is published! I'll try and publish it all again.

  • Dominic Kelly 114 posts 133 karma points
    Jan 16, 2012 @ 18:56
    Dominic Kelly
    0

     

        if (@Model.HasProperty("internalPromotions"))

        {

            string[] nodes = @Model.GetPropertyValue("internalPromotions").Split(',');

     

            foreach (string nodeId in nodes)

            {

                var curNode = @Model.NodeById(nodeId);

                <p>current node id:  @nodeId</p>

                <p>current node id:  @curNode.Name</p>

            }    

       }

     

    So, @nodeId is correct, @curNode.Name is empty.

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 16, 2012 @ 18:58
    Tom Fulton
    0

    That's strange.  You could try making a test macro somewhere with just the two lines to isolate the problem.  If it fails I suspect you have bigger problems :)

    @{
      var testNode = Library.NodeById(1234); // put the id of the node that's failing here...
      <p>@testNode.Name</p>
    }
  • Dominic Kelly 114 posts 133 karma points
    Jan 16, 2012 @ 19:03
    Dominic Kelly
    0

    @{

      var testNode = Library.NodeById(1104); // put the id of the node that's failing here...

      <p>@testNode.Name</p>

    }

    Where 1104 is the id of a file in the media library works correctly.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 16, 2012 @ 19:05
    Tom Fulton
    0

    Are you testing with the same Node ID that is missing in your other example?  I don't see why it would show there but not in your test

  • Dominic Kelly 114 posts 133 karma points
    Jan 16, 2012 @ 19:07
    Dominic Kelly
    0

    Yup.

           foreach (string nodeId in nodes)

           {

               var curNode = Library.NodeById(nodeId);

               <p>current node id:  @curNode.Name</p>

            }

    Doesn't work.

           foreach (string nodeId in nodes)

           {

               var curNode = Library.NodeById(1104);

               <p>current node id:  @curNode.Name</p>

            }

    Does work.

  • Dominic Kelly 114 posts 133 karma points
    Jan 16, 2012 @ 19:28
    Dominic Kelly
    0

    So the question is why on earth can't I pass in a variable containing an id, but can pass in the value directly.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 16, 2012 @ 19:32
    Tom Fulton
    0

    I'm kind of at a loss here :)

    If the nodeId is "1104" in the first example (have you verified that?) I don't see why it would work in #2 but not #1...there should be no reason for that.  The only difference is it's a string in the first example, but you could test also like Library.NodeById("1104") but there should be no difference.

    It sounds like we're either missing something simple or you have some other issues with your site.  I don't know what type of site this is but is it possible to give me access temporarily?  I would gladly take a quick look for you.  If that's possible just hit me up on twitter...

    -Tom

     

  • Dominic Kelly 114 posts 133 karma points
    Jan 16, 2012 @ 19:36
    Dominic Kelly
    0

    Sure!! My twitter is dominic_kelly.

    Library.NodeById("1104") and Library.NodeById(1104) both work, whereas Library.NodeById(nodeId); does not. 

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 16, 2012 @ 19:56
    Tom Fulton
    0

    In case anyone else is following this, we got it worked out via twitter, turned out the nodes selected weren't fully published (link to document was #) and this weren't available for Razor.  Re-publishing each node fixed the issue.

    whew... :)

Please Sign in or register to post replies

Write your reply to:

Draft