Copied to clipboard

Flag this post as spam?

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


  • Jeremy Holland 20 posts 103 karma points
    Nov 19, 2019 @ 20:03
    Jeremy Holland
    1

    Best way to get boolean from page fields and macro parameters

    Hi,

    I'm trying to get a boolean value from both the current page field and a macro parameter (which is on the same page). Using this code I was able to do it:

    bool adsOn = Model.MacroParameters["adsEnabled"].ToString() != "0";
    bool globalAdsOn = Model.Content.GetProperty("adsEnabled").Value().ToString().ToLower() != "false";
    

    But this feels unnecessarily verbose. Is there a better way to do this?

    Thanks!

    Edit: I also noticed if the macro parameter has never been set to true or false, the value returned is true even the UI shows the toggle set to false.

Please Sign in or register to post replies

Write your reply to:

Draft