Copied to clipboard

Flag this post as spam?

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


  • Anthony Candaele 1197 posts 2049 karma points
    Apr 09, 2014 @ 17:34
    Anthony Candaele
    0

    remove spaces

    Hi, does the Umbraco library have a helper method for removing spaces from a string?

    I have this dynamicaly generated url in my page:

    <a href='tel:0472 24 65 02'>0472 24 65 02</a></li>
    

    but the W3C validation service is complaining about the spaces in the href attribute

    Thanks for your help,

    Anthony

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Apr 09, 2014 @ 17:52
    Jeavon Leopold
    1

    No it doesn't, but how about:

    @{
        var telNumber = "0472 24 65 02";            
        <li><a href='tel:@telNumber.Replace(" ", string.Empty)'>@telNumber</a></li>               
    }
    

    Jeavon

  • Anthony Candaele 1197 posts 2049 karma points
    Apr 09, 2014 @ 18:00
    Anthony Candaele
    0

    Hi Jeavon,

    Thanks, I tried this:

      <h1>@Umbraco.Field("footerTitle2", recursive: true)</h1>
                <ul class="contact">
                    @{
                        var telNumber = @Umbraco.Field("footerPhone", recursive: true); 
                    }
                  <li>Zuidlaan 54, 8370 Blankenberge</li>
                  <li><i class="fa fa-phone-square"></i>&nbsp;&nbsp;<a href='tel:@telNumber.Replace(" ", string.Empty)'>@Umbraco.Field("footerPhone", recursive: true)</a></li>
                  <li><i class="fa fa-envelope"></i>&nbsp;&nbsp;<a href='mailto:@Umbraco.Field("footerEmail", recursive: true)'>@Umbraco.Field("footerEmail", recursive: true)</a>       </li>
                </ul>
    

    But I'm getting this error:

    CS1501: No overload for method 'Replace' takes 2 arguments
    
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Apr 09, 2014 @ 18:06
    Jeavon Leopold
    0

    Ah sure, should be like this

                @{
                    var telNumber = Model.Content.GetPropertyValue<string>("footerPhone", true); 
                }
    
  • Anthony Candaele 1197 posts 2049 karma points
    Apr 09, 2014 @ 18:19
    Anthony Candaele
    0

    does that work in a Razor template file? I'm not working in a Macro Partial File.

    when I add this in Visual Studio, I'm getting this error:

    enter image description here

    I tried this, and that works:

    <ul class="contact">
      @{
      var telNumber = Umbraco.Field("footerPhone", recursive: true); 
    }
        <li>Zuidlaan 54, 8370 Blankenberge</li>
        <li><i class="fa fa-phone-square"></i>&nbsp;&nbsp;<a href='tel:@telNumber.ToString().Replace(" ", string.Empty)'>@Umbraco.Field("footerPhone", recursive: true)</a></li>
         <li><i class="fa fa-envelope"></i>&nbsp;&nbsp;<a href='mailto:@Umbraco.Field("footerEmail", recursive: true)'>@Umbraco.Field("footerEmail", recursive: true)</a></li>
      </ul>
    
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Apr 09, 2014 @ 18:38
    Jeavon Leopold
    0

    Ok, if that works, stick with it :-) I will check on GetPropertyValue later when I have a computer (currently on iPad), but it should work perfectly.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Apr 09, 2014 @ 19:35
    Jeavon Leopold
    100

    Hey Anthony,

    Ok, figured it, in Umbraco v7 you can do what I posted but in v6 you have to have a additional parameter (what to return if nothing found recursively) like this:

    <h1>@Umbraco.Field("footerTitle2", recursive: true)</h1>
    <ul class="contact">
        @{
           var telNumber = Model.Content.GetPropertyValue<string>("footer", true, string.Empty);
        }
        <li>Zuidlaan 54, 8370 Blankenberge</li>
        <li><i class="fa fa-phone-square"></i>  <a href='tel:@telNumber.Replace(" ", string.Empty)'>@telNumber</a></li>
        <li><i class="fa fa-envelope"></i>  <a href='mailto:@Umbraco.Field("footerEmail", recursive: true)'>@Umbraco.Field("footerEmail", recursive: true)</a>       </li>
    </ul>
    

    Nice little improvement in v7 there :-)

    Jeavon

  • Anthony Candaele 1197 posts 2049 karma points
    Apr 10, 2014 @ 14:40
    Anthony Candaele
    0

    Thanks Jeavon,

    works like a charm : )

    greetings,

    Anthony

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Apr 10, 2014 @ 14:43
    Jeavon Leopold
    0

    Awesome! In case someone finds this useful in the future I should add that this Model.Content.GetPropertyValue<string>("footerPhone", true) method works in v6.2+

Please Sign in or register to post replies

Write your reply to:

Draft