Copied to clipboard

Flag this post as spam?

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


  • Bjarne Fyrstenborg 1182 posts 3441 karma points MVP 4x c-trib
    Sep 26, 2013 @ 18:52
    Bjarne Fyrstenborg
    0

    Get each "column" value in textstring array

    I am using uComponents textstring array datatype to list social media icons with a url and a value..

    I have used the razor example from here http://ucomponents.org/data-types/textstring-array/ but I can't figure out how to get each specific value in a row?

    In the xslt example the syntax is value[1] and value[2], but in the razor example @cell outputs all values in the row.. how can I get each value node?

    <TextstringArray>
        <values>
            <value>hello</value>
            <value>world</value>
        </values>
        <values>
            <value>foo bar</value>
            <value>world</value>
        </values>
    </TextstringArray>

    /Bjarne

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Sep 26, 2013 @ 22:15
    Jeavon Leopold
    0

    Hi Bjarne,

    Give this a try:

     <table>
        @foreach (var row in textstringArrayPropertyAlias)
        {
            <tr>         
                @foreach (var cell in row)  
                {   
                    <td>@cell.InnerText</td>
                }
            </tr>
        }
    </table> 
    

    Jeavon

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Sep 26, 2013 @ 22:23
    Jeavon Leopold
    0

    I should explain further, the example is using the Razor Model Binding but if you don't have that enabled (or are using Mvc), the type will be DynamicXml which I think is what you have.

    Are you using Mvc?

  • Bjarne Fyrstenborg 1182 posts 3441 karma points MVP 4x c-trib
    Sep 26, 2013 @ 22:27
    Bjarne Fyrstenborg
    0

    Hi Jeavon

    I also tried that, but I then get a error that string doesn't contains a defination for InnerText.

    Right now I have this:

    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    <div class="footerText">
    <ul>
        @foreach (string[] row in Model.NodeById(1054).socialNetworks)
        {
            <li>
                @foreach (var cell in row)
                {
                    @cell;
                }
            </li>
        }
    </ul>
    </div>

    Which outputs this:

    <div class="footerText">
    <ul>
    <li>Facebookhttps://www.facebook.com</li>
            <li>Instagramhttp://instagram.com/</li>
    </ul>
    </div>

    I would like to split the values up into something like this:

    <div class="footerText">
    <ul>
    <li><a href="https://www.facebook.com" target="_blank" title="Facebook">Facebook</a></li>
            <li><a href="http://instagram.com/" target="_blank" title="Instagram">Instagram</a></li>
    </ul>
    </div>

    /Bjarne

  • Bjarne Fyrstenborg 1182 posts 3441 karma points MVP 4x c-trib
    Sep 26, 2013 @ 22:30
    Bjarne Fyrstenborg
    0

    No, the rendering engine is set to WebForms :)

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Sep 26, 2013 @ 22:34
    Jeavon Leopold
    0

    Ok, so you have the uComponents Razor Model Binding set to true in Web.Config?

  • Bjarne Fyrstenborg 1182 posts 3441 karma points MVP 4x c-trib
    Sep 26, 2013 @ 22:41
    Bjarne Fyrstenborg
    0

    I haven't a key in with that in web.config, but I think it's activated since a see this message under uComponents activator dashboard tab:

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Sep 26, 2013 @ 22:53
    Jeavon Leopold
    0

    Have you tried?

    @foreach (string[] row in Model.NodeById(1054).socialNetworks)
    {
        <li>
            @foreach (var cell in row)
            {
                @cell[0] @cell[1]
            }
        </li>
    }
    
  • Bjarne Fyrstenborg 1182 posts 3441 karma points MVP 4x c-trib
    Sep 26, 2013 @ 23:17
    Bjarne Fyrstenborg
    0

    Yep.. tried that too.. but I think it gives me a weird output ..

    <div class="footerText"> 
       <ul>
          <li>Faht</li>
          <li>Inht</li>
       </ul>
    </div>

    It seems to take the two first characters Fa from Facebook and ht from http://facebook.com .. and the for Instagram in this case..

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Sep 26, 2013 @ 23:26
    Jeavon Leopold
    100

    Ok, one last go for today:

    @foreach (string[] row in Model.NodeById(1054).socialNetworks)
    {
        <li>
            @row[0] @row[1]
        </li>
    }
    
  • Bjarne Fyrstenborg 1182 posts 3441 karma points MVP 4x c-trib
    Sep 26, 2013 @ 23:39
    Bjarne Fyrstenborg
    0

    Ahh, that looks much more pretty :)

    <div class="footerText">
       <ul>
          @foreach (string[] row in Model.NodeById(1054).socialNetworks)
          {
             <li>
                 <a href="@row[1]" target="_blank" title="@row[0]">@row[0]</a>
         </li>
          }
       </ul>
    </div>

    Output:

    <div class="footerText"> 
       <ul>
          <li>
                 <a href="http://facebook.com" target="_blank" title="Facebook">Facebook</a>
          </li>
          <li>
                 <a href="http://instagram.com" target="_blank" title="Instagram">Instagram</a>
          </li>
       </ul>
    </div>

     

    Thanks.. just what I was looking for.. :)

    /Bjarne

     

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Sep 26, 2013 @ 23:50
    Jeavon Leopold
    0

    Phew! Glad it's working now.

    Jeavon

  • 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