Copied to clipboard

Flag this post as spam?

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


  • Johan Plesner Hamann 105 posts 199 karma points
    Jun 29, 2011 @ 22:06
    Johan Plesner Hamann
    0

    @foreach value of Multiple Textstring - uComponents

     

    I have some values from  uComponents Multiple Textstring

      <kursusHvornaar>
                <values>
                  <value>4. - 5. april 2011</value>
                  <value>24. - 25. oktober 2011</value>
                </values>
       </kursusHvornaar>

    and I cannot foreach et out in Razor

    please help!

    /Johan

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jun 29, 2011 @ 22:41
    Dirk De Grave
    4

    Hi,

    Try this:

    <ul>
    @foreach (var x in Model.kursusHvornaar) {
      <li>@x.InnerText</li>
    }
    </ul>

    Hope this helps.

    Regards;

    /Dirk

  • Johan Plesner Hamann 105 posts 199 karma points
    Jun 29, 2011 @ 22:52
    Johan Plesner Hamann
    0

    Thank you Dirk

    the magic word is InnerText

    you just made my night. 

    have spent some time and I can not search from google into our?!

    /Johan

  • Jan Vermeerbergen 79 posts 112 karma points
    Aug 25, 2011 @ 10:22
    Jan Vermeerbergen
    0

    Hi Dirk,

    thanks for your info here.

    Just one more question: Would there also be an XSLT-variant to getting these values from a Multiple textstring? 

     

    /Jan

  • Johan Plesner Hamann 105 posts 199 karma points
    Aug 31, 2011 @ 21:05
    Johan Plesner Hamann
    0

    use this link it should be the same... almost.

    /Johan

  • wolulcmit 357 posts 693 karma points
    Nov 08, 2011 @ 04:23
    wolulcmit
    0

    Um, how would you only output the first value and not the second?

    so in the example above you only wanted to output

    4. - 5. april 2011

    and not

    24. - 25. oktober 2011

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 08, 2011 @ 08:54
    Dirk De Grave
    1

    tim,

    Depends on the umbraco version, cause the latest version have a better Razor support for uComponents datatypes. Can't find any example code atm, but to get you started (quick win), you could introduce a flag to indicate whether you've already processed an item and if flag is set to true, just don't output the <li> block?

    I'm sure there's better solutions out there...

    @{ var processed = false; }
    <ul>
    @foreach (var x in Model.kursusHvornaar) { 
      if (!processed) {
        <li>@x.InnerText</li>
        processed = true;
      }
    }
    </ul>

    Cheers,

    /Dirk

     

  • wolulcmit 357 posts 693 karma points
    Nov 08, 2011 @ 10:20
    wolulcmit
    0

    Hey Dirk, am using 4.7.1 with uComponents 3.0

    thanks for that - I got it working! with the example above.

    If anyone is curious I wanted to loop through a uComponents textString array and have different loops for different languages.
    might be a bit of a silly way of doing things. I tend to do things arse about face sometimes :)

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Dec 22, 2011 @ 22:58
    Tom Fulton
    0

    Hey Tim,

    Can you explain how you're getting each cell with Textstring Array?  The example above is for Multiple Textstring which only has one value per row.  I can't seem how to figure out how to get each "cell"/value using Textstring Array such as in your screenshot.

    I thought it would be something like:

    foreach (var time in Model.homeServiceTimes)
    {
    <p>@time.value[0].InnerText</p>
    <p>@time.value[1].InnerText</p>
    }

    but this throws an error: 'char' does not contain a definition for 'InnerText'

    Can you share how you achieved this?

    Thanks,
    Tom

  • wolulcmit 357 posts 693 karma points
    Dec 23, 2011 @ 02:29
    wolulcmit
    1

    Hi Tom,

    I'm doing the following:

    @* get us a counter so we can set up a loop *@
    var count = 0;
    foreach (var counter in item.questionContent)
    {
    count = count + 1;
    }

    @
    * Loop through the bastards*@
    for (int i = 0; i < count; i++){
    @foreach
    (var qLoop in item.questionContent[i]){
    @qLoop.InnerText
    }

    Hope that helps!

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Dec 23, 2011 @ 03:39
    Tom Fulton
    0

    Thanks Tim, that does the trick.  Although I think there must be an easier way to do it.  In my current situation I want to write something like this for each row in the array

    <strong>Cell 1:</strong> Cell 2<br/>

    I think with your code above I'd need to add another counter in the inner loop and test to know when to use the strong.  I would think I should be able to do something like

    foreach (var qLoop in item.questionContent)
    {
    <strong>@qLoop.value[0] : </strong>@qLoop.value[1]<br/>
    }

    But I can't figure out how to do that.  Any ideas?  But your code has got me started for now, thanks :)

    -Tom

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Dec 23, 2011 @ 14:46
    Tom Fulton
    0

    ...could have sworn I tried this, but I guess not.  This works fine:

    foreach(var qLoop in item.questionContent)
    {
    <strong>@qLoop[0].InnerText</strong>: @qLoop[1].InnerText<br/>
    }

    Thanks again!
    Tom

  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 18, 2012 @ 11:51
    Fuji Kusaka
    0

    Hi Tom,

    Am having some issues displaying the first value of a multipleTextString in v4.9.1. 

    foreach(var photos in folder.Children.OrderBy("id, desc")){
    @photos.value[0].InnerText
    }
  • Tom Fulton 2030 posts 4998 karma points c-trib
    Dec 19, 2012 @ 17:28
    Tom Fulton
    0

    Hi Fuji,

    I've not tested in 4.9, but looking at your code, it looks like you need to get the property somewhere, photos would be the doc/media item right?

    foreach(var photos in folder.Children.OrderBy("id, desc")){
    @photos.yourPropertyAlias.value[0].InnerText
    }

    -Tom

  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 20, 2012 @ 20:15
    Fuji Kusaka
    0

    Nope did get this to work either. 

    But if i do something like 

    @photos.yourPropertyAlias // get all the values
    @photos.yourPropertyAlias.value[0]  @photos.yourPropertyAlias.value[0].InnerText //doesnt work 
  • Dovile 2 posts 22 karma points
    Aug 04, 2014 @ 16:12
    Dovile
    0

    The one worked for me was:

    @foreach(var x in Model.arrayPropertyAlias) {

    <strong>@x[0]</strong> <p>@x[1]</p>

    }

Please Sign in or register to post replies

Write your reply to:

Draft