Copied to clipboard

Flag this post as spam?

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


  • Peter Alcock 106 posts 169 karma points
    Jan 19, 2012 @ 13:52
    Peter Alcock
    0

    Displaying Umbraco field

    Hi all,

    Loooking for a bit of help, i have a carousel (uses nivoslider package) which i am altering slightly.

    What im trying to do is get it to display the contents on the RTE Small field named 'textBox' within the carousel.

    foreach (dynamic img in nodes.Children)
        {
            if (img.HasValue("nivoSliderCaption"))
            {
                    <div id="@img.Name" class="nivo-html-caption">
                        @Html.Raw(img.nivoSliderCaption)
                    </div>                         
            }
           
            if (img.HasValue("textBox"))
            {
                   <div class="nivotext">
                        ("<umbraco:Item field="textBox" runat="server"></umbraco:Item>")
                        </div>                         
            }

        }

    The caption works all fine and for the if (img.HasValue("textBox")) if i just use some plain text for example

      if (img.HasValue("textBox"))
            {
                   <div class="nivotext">
                        @Html.Raw("hello")
                        </div>                         
            }

    It works fine and displays, but i want it to display the contents of the 'textBox' field, any ideas?

    Thanks

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Jan 19, 2012 @ 14:04
    Jeroen Breuer
    0

    Hmm I could be wrong, but won't this just work?

    if (img.HasValue("textBox"))
    {
        <div class="nivotext">
               @img.textBox
        </div>                          
    }

    Jeroen

  • Rodion Novoselov 694 posts 859 karma points
    Jan 19, 2012 @ 14:23
    Rodion Novoselov
    0

    Little note of mine - since it's RTE it looks a bit more correct to use:

    <div class="nivotext">
    @Html.Raw(img.textBox)
    </div> 

     

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Jan 19, 2012 @ 14:25
    Jeroen Breuer
    0

    Why would you add Html.Raw to it? I thought RTE properties would work anyway.

    Jeroen

  • Rodion Novoselov 694 posts 859 karma points
    Jan 19, 2012 @ 14:33
    Rodion Novoselov
    0

    RTE text has a markup inside it - I suspect that its output through @img.textBox will be HTML-escaped. (And that's well-known Razor drawback - it still has no short syntax for unescaped output (like "<%=" vs "<%:" in legacy ASP.NET rendering engine).

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Jan 19, 2012 @ 14:44
    Sebastiaan Janssen
    2

    Nah, for the built-in Rich text editor datatype, Umbraco will automatically output the Raw HTML if you do @img.textBox.

  • Peter Alcock 106 posts 169 karma points
    Jan 19, 2012 @ 15:02
    Peter Alcock
    0

    Cheers for all the help, to make life easier ive just changed from RTE to textbx multiple which still does everything i want it to do so all working brilliantly now!

    thanks for the help!

  • Rodion Novoselov 694 posts 859 karma points
    Jan 19, 2012 @ 16:05
    Rodion Novoselov
    0

    Sebastian, you have turned up to be right. I've just validate it (I like making everything sure on my own :-)) Text properties of a DynamicNode etc are returned as HtmlString, so there's really no need to bother about HTML encoding. Thanks for a tip.

  • 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