Copied to clipboard

Flag this post as spam?

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


  • Balram Narad 37 posts 89 karma points
    Mar 12, 2014 @ 12:48
    Balram Narad
    0

    Looping through properties

    Hi

    I'm new to umbraco and using umbraco 6.1.6, I am trying to create a partialview that will create a grid of boxes with content. 

    In my partialview I want to loop through and get the content from each of the properties on the current node.

    e.g my content has properties title1, title2, title3and I would like to do something like the following

    @{
    for (int i = 0; i < mainCount; i++)
    {
    <h1>@Umbraco.Field("title @i")</h1>

    but I don't seem to be able to join the property name with the i variable

    I hope that makes some sense any help gratefully recieved

    Bal

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 12, 2014 @ 12:50
    Jeavon Leopold
    0

    Hi Balram and welcome to Our!

    Try this:

    <h1>@Umbraco.Field("title" + i)</h1>
    

    Jeavon

  • Balram Narad 37 posts 89 karma points
    Mar 12, 2014 @ 12:55
    Balram Narad
    0

    that's great I could have sworn I'd tried that but it has worked now

     

    thanks

     

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 12, 2014 @ 12:56
    Jeavon Leopold
    0

    Great!

  • Balram Narad 37 posts 89 karma points
    Aug 20, 2014 @ 13:01
    Balram Narad
    0

    Hi Again

    I've got another similar problem this time when I am trying to get a property using CurrentPage.PropertyValue.  I am using the DAMP media picker to have an image for each block on a page.  See code below.

      @if (CurrentPage.HasProperty("blockimage"+i) && CurrentPage.HasValue("blockimage"+i))

                {

                        foreach (dynamic itemPhoto in CurrentPage.blockimage1)

                    {                                

                    <img src="@CropUp.GetUrl(@itemPhoto.Url, new ImageSizeArguments { CropAlias = "gallery" })" alt="@itemPhoto.Alt" class="img-polaroid" />

                    }

                }

       This works but I need to replace the 1 in this line   foreach (dynamic itemPhoto in CurrentPage.blockimage1) with the value of i  

     

    any help appreciated

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 20, 2014 @ 13:12
    Jeavon Leopold
    0

    I'm pretty sure you need this:

    foreach (dynamic itemPhoto in CurrentPage.GetPropertyValue("blockimage" + i))
    
  • Balram Narad 37 posts 89 karma points
    Aug 20, 2014 @ 13:20
    Balram Narad
    0

    When I do the above I get a different error

     'char' does not contain a definition for 'Url' so I'm not sure what is happening

    the CurrentPage.blockimage1 works okay but CurrentPage."blockimage"+i does not

    Bal

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 20, 2014 @ 13:45
    Jeavon Leopold
    0

    Are you using the DAMP value converter?

  • Balram Narad 37 posts 89 karma points
    Aug 21, 2014 @ 18:40
    Balram Narad
    0

    yes I am

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 21, 2014 @ 18:44
    Jeavon Leopold
    0

    Ok, give this a try then:

    foreach (var itemPhoto in CurrentPage.GetPropertyValue<DAMP.PropertyEditorValueConverter.Model>("blockimage" + i))
    
  • Balram Narad 37 posts 89 karma points
    Aug 21, 2014 @ 18:56
    Balram Narad
    0

    HI Jeavon

    When I do this I get the char' does not contain a definition for 'Url' error again I'm beginning to think the problem may lay elsewhere thanks for your help so far though

    Bal

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 21, 2014 @ 19:00
    Jeavon Leopold
    0

    Could you try it strongly typed:

    @if (Model.Content.HasProperty("blockimage" + i) && Model.Content.HasValue("blockimage" + i))
    {
    
        foreach (var itemPhoto in Model.Content.GetPropertyValue<DAMP.PropertyEditorValueConverter.Model>("blockimage" + i))
        {
    
            <img src="@CropUp.GetUrl(itemPhoto.Url, new ImageSizeArguments { CropAlias = "gallery" })" alt="@itemPhoto.GetPropertyValue("Alt")" class="img-polaroid" />
    
        }
    
    }
    
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 21, 2014 @ 19:01
    Jeavon Leopold
    0

    Please use edited above

  • Balram Narad 37 posts 89 karma points
    Aug 22, 2014 @ 10:35
    Balram Narad
    0

    That's great thanks Jeavon

     

    Bal

  • 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