Copied to clipboard

Flag this post as spam?

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


  • Kieron 152 posts 390 karma points
    Mar 27, 2018 @ 16:12
    Kieron
    0

    Cant use ToLower() within Macro

    Hello, as in title, currently struggling to use the GetPropertyValue with ToLower, so as below, stripped the bulk of it out, but on the Section slightly further down you can see @item.GetProperty("target").ToLower() and this renders on the page where we have the macro as

    Error loading Partial View script (file: ~/Views/MacroPartials/Campaign Section.cshtml)
    

    Hopefully someone can help, cheers

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
        string passFeature = Model.MacroParameters["isFeatured"].ToString();
    
        if(@passFeature == "1"){
    
            foreach(var item in Umbraco.TypedContent(1853).Children().Where(x => x.IsVisible() && x.GetPropertyValue<bool>("featureOnHomePage"))){
    
            <section class="section th-dark [email protected]("target").ToLower()">
                <div class="section-row-container">
                    <div class="section-row th-light half-padding-top half-padding-bottom bg-transparent">
                        </div>      
                            </div>
                        </div>
                    </div>
                </div>
            </section>
    
            }
    
        } else {
    
            foreach(var item in Umbraco.TypedContent(1853).Children().Where(x => x.IsVisible())){
    
    
            }
        }
    
    }
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 27, 2018 @ 16:23
    Alex Skrypnyk
    101

    Hi Kieron

    Use this code:

    <section class="section th-dark bg-call-to-@(item.GetPropertyValue<string>("target").ToLower())">
    

    Thanks,

    Alex

  • Kieron 152 posts 390 karma points
    Mar 28, 2018 @ 08:01
    Kieron
    0

    Hey Alex, thanks for that, we had solved it just after you posted also but it was a different solution, we went with;

    @item.GetProperty("target").DataValue.ToString().ToLower()
    

    Can you see any disadvantages to this method?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 28, 2018 @ 08:22
    Alex Skrypnyk
    1

    Hi Kieron

    It's basically the same, so just how do you like more :)

    Just be sure that there are no nulls :)

    Thanks,

    Alex

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 27, 2018 @ 16:25
    Alex Skrypnyk
    1

    Also, be sure that

     item.GetPropertyValue<string>("target") 
    

    isn't NULL, because .ToLower() will give you an exception

Please Sign in or register to post replies

Write your reply to:

Draft