Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    May 16, 2013 @ 09:47
    Fuji Kusaka
    0

    Slipt Multiple Text String

    Hi ,

    I have a multiple textString in v4.9.1 where i use * as symbol to split the content of each textString.

    So far it works well but when view the source i realised the output also added this

    <h1><values><value> some text </h1> but only for the first TextString.
    @foreach(var t in f.GetProperty("caption").Value.Split("*".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)){   <h1>@Library.StripHtml(t) </h1>   }
  • Lee Kelleher 4024 posts 15833 karma points MVP 13x admin c-trib
    May 16, 2013 @ 10:26
    Lee Kelleher
    0

    Hi Fuji,

    Are you still using uComponents?  If so, check if you have the "uComponents.Legacy.dll" in your /bin folder.  If so, then you could do this:

    namespace Our.Umbraco
    {
        using uComponents.Core.DataTypes.MultipleTextstring; // for v4.x
        // using uComponents.DataTypes.MultipleTextstring; // for v5.x
        using umbraco.editorControls;
        using umbraco.MacroEngines;
    
        [RazorDataTypeModel(DataTypeGuids.MultipleTextstringId)]
        public class MyMultipleTextstringModelBinder : MultipleTextstringModelBinder
        {
        }
    }

    Copy-n-paste that into a separate C# class (either drop it into your /App_Code folder - or if you already have other compiled code, put it in there)

    What this does is convert the Multiple Textstring into a list of strings. Then you can use it in your Razor scripts, like so:

    @foreach(var t in f.GetProperty("caption").Value)
    {
        <h1>@Library.StripHtml(t)</h1>
    }

    Cheers, Lee.

  • Fuji Kusaka 2203 posts 4220 karma points
    May 16, 2013 @ 11:25
    Fuji Kusaka
    0

    Hi Lee,

    No am using the custom Multiple TextString in v4.9.1. So i just need to make use of the namespace uComponents ? or do i need to install uComponents?

  • Lee Kelleher 4024 posts 15833 karma points MVP 13x admin c-trib
    May 16, 2013 @ 11:29
    Lee Kelleher
    1

    Hi Fuji,

    No problem - don't worry about installing uComponents :-)

    You can add in the custom Razor Model Binder code (from uComponents) https://ucomponents.codeplex.com/SourceControl/latest#uComponents.Legacy/DataTypes/MultipleTextstring/MultipleTextstringModelBinder.cs

    using System.Collections.Generic;
    using System.Xml;
    using umbraco.MacroEngines;
    
    namespace Our.Umbraco
    {
        [RazorDataTypeModel(DataTypeGuids.MultipleTextstringId)]
        public class MultipleTextstringModelBinder : IRazorDataTypeModel
        {
            public bool Init(int CurrentNodeId, string PropertyData, out object instance)
            {
                var values = new List<string>();
    
                if (!string.IsNullOrEmpty(PropertyData))
                {
                    var xml = new XmlDocument();
                    xml.LoadXml(PropertyData);
    
                    foreach (XmlNode node in xml.SelectNodes("/values/value"))
                    {
                        values.Add(node.InnerText);
                    }
                }
    
                instance = values;
    
                return true;
            }
        }
    }
    

    Do keep in mind that if you use this code, it will convert all of your Multiple Textstring values into a proper strongly-typed model. :-)

    Cheers, Lee.

  • Fuji Kusaka 2203 posts 4220 karma points
    May 16, 2013 @ 11:43
    Fuji Kusaka
    0

    Any Specific naming convention for this Lee ?? Or i just drop it in my App_code folder ?

     

    Thanks 

  • Lee Kelleher 4024 posts 15833 karma points MVP 13x admin c-trib
    May 16, 2013 @ 11:45
    Lee Kelleher
    0

    Just call it "MultipleTextstringModelBinder.cs" and drop it in your /App_Code folder.

    Cheers, Lee.

  • Fuji Kusaka 2203 posts 4220 karma points
    May 16, 2013 @ 12:27
    Fuji Kusaka
    0

    Hmm, Am getting an ugly server error though

    CS0103: The name 'DataTypeGuids' does not exist in the current context
    namespace Our.Umbraco
    Line 6:  {
    Line 7:      [RazorDataTypeModel(DataTypeGuids.MultipleTextstringId)]
    Line 8:      public class MultipleTextstringModelBinder : IRazorDataTypeModel
    Line 9:      {
  • Lee Kelleher 4024 posts 15833 karma points MVP 13x admin c-trib
    May 16, 2013 @ 12:33
    Lee Kelleher
    0

    Ah, change it to:

    [RazorDataTypeModel(umbraco.editorControls.DataTypeGuids.MultipleTextstringId)]
  • Fuji Kusaka 2203 posts 4220 karma points
    May 16, 2013 @ 12:48
    Fuji Kusaka
    0

    Thanks Lee but still not working though

    This 

    @foreach(var t in f.GetProperty("sliderImageCaption").Value){ @Library.StripHtml(f.GetProperty("sliderImageCaption").Value) }
    Output 
    t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2t 1 t 2

    Instead of t1 t2 

    and if  i change it to @Library.StripHtml(t) i get some errors while saving

    error CS1502: The best overloaded method match for 'umbraco.MacroEngines.Library.RazorLibraryCore.StripHtml(System.Web.IHtmlString)' has some invalid arguments
  • Lee Kelleher 4024 posts 15833 karma points MVP 13x admin c-trib
    May 16, 2013 @ 12:51
    Lee Kelleher
    0

    Could try removing the @Library.StripHtml?  (I'm not sure what it is expecting for an input)

  • Fuji Kusaka 2203 posts 4220 karma points
    May 16, 2013 @ 13:00
    Fuji Kusaka
    0

    Am basically using this in a javascript. When removing the symbol * for the split to work i get this

    @foreach(var t in f.GetProperty("sliderImageCaption").Value.Split("*".ToCharArray())){ <h1>@Library.StripHtml(f.GetProperty("sliderImageCaption").Value)</h1>  }

    output 

    <h1>t 1 *t 2</h1>   <h1>t 1 *t 2</h1>

    And if i use this 

    @foreach(var t in f.GetProperty("sliderImageCaption").Value.Split("*".ToCharArray())){ <h1>@Library.StripHtml(t)</h1> 
    <h1><values><value>t 1 </h1>   <h1>t 2</h1>

    But am looking for and output like 

    <h1>t 1 </h1>   <h1>t 2</h1>
  • Lee Kelleher 4024 posts 15833 karma points MVP 13x admin c-trib
    May 16, 2013 @ 13:05
    Lee Kelleher
    0

    Hi Fuji,

    I'm assuming that you now have the model binding code in place?  If so, then you don't need to split the string yourself - that will already be done for you.

    So this should work...

    @foreach(var item in f.GetProperty("caption").Value)
    {
        <h1>@item </h1>
    }

    If that doesn't work - then I'm not sure what the answer is. :-(

  • Fuji Kusaka 2203 posts 4220 karma points
    May 16, 2013 @ 13:28
    Fuji Kusaka
    0

    Nope this output :(

    <h1> &lt;</h1>   <h1> v</h1>   <h1> a</h1>   <h1> l</h1>   <h1> u</h1>   <h1> e</h1>   <h1> s</h1>   <h1> &gt;</h1>   <h1> &lt;</h1>   <h1> v</h1>   <h1> a</h1>   <h1> l</h1>   <h1> u</h1>   <h1> e</h1>   <h1> &gt;</h1>   <h1> t</h1>   <h1>  </h1>   <h1> 1</h1>   <h1> &lt;</h1>   <h1> /</h1>   <h1> v</h1>   <h1> a</h1>   <h1> l</h1>   <h1> u</h1>   <h1> e</h1>   <h1> &gt;</h1>   <h1> &lt;</h1>   <h1> v</h1>   <h1> a</h1>   <h1> l</h1>   <h1> u</h1>   <h1> e</h1>   <h1> &gt;</h1>   <h1> t</h1>   <h1>  </h1>   <h1> 2</h1>   <h1> &lt;</h1>   <h1> /</h1>   <h1> v</h1>   <h1> a</h1>   <h1> l</h1>   <h1> u</h1>   <h1> e</h1>   <h1> &gt;</h1>   <h1> &lt;</h1>   <h1> /</h1>   <h1> v</h1>   <h1> a</h1>   <h1> l</h1>   <h1> u</h1>   <h1> e</h1>   <h1> s</h1>   <h1> &gt;</h1>
  • Lee Kelleher 4024 posts 15833 karma points MVP 13x admin c-trib
    May 16, 2013 @ 13:29
    Lee Kelleher
    0

    Hmm... doesn't seem like the model-binder code is working. :-(

    Let me find some code which might help :-)

  • Lee Kelleher 4024 posts 15833 karma points MVP 13x admin c-trib
    May 16, 2013 @ 13:51
    Lee Kelleher
    0

    I found this other forum post about using Multiple Textstring values with Razor... quite a few code snippets in there:

    http://our.umbraco.org/forum/developers/razor/21753-@foreach-value-of-Multiple-Textstring-uComponents-

  • Fuji Kusaka 2203 posts 4220 karma points
    May 16, 2013 @ 13:55
    Fuji Kusaka
    0

    Ive tried those as well!!

    But here am using DynamicNode. Forgot to mention if a down make use of the Split * in the TextString it doesnt split up.

Please Sign in or register to post replies

Write your reply to:

Draft