Copied to clipboard

Flag this post as spam?

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


  • Steve 472 posts 1216 karma points
    Aug 08, 2014 @ 20:21
    Steve
    0

    Ternary Operator Check for String.IsNullOrEmpty

    I thought I had the correct syntax for this ternary operator to check for an empty parameter, but as it is the value that I have for the defaults always override the parameter value. What have I done wrong?

    var StartLevel = String.IsNullOrEmpty(Parameter.startLevel) ? 4 : int.Parse(Parameter.startLevel);

    var FinishLevel = String.IsNullOrEmpty(Parameter.finishLevel) ? 6 : int.Parse(Parameter.finishLevel);

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Aug 08, 2014 @ 20:35
    Jeavon Leopold
    0

    There is nothing wrong with this. Are you sure that Parameter.startLevel is the correct parameter alias and has a value?

  • Steve 472 posts 1216 karma points
    Aug 08, 2014 @ 21:15
    Steve
    0

    Yes, here is the macro on the template. It won't go to level 7 unless I change the defalut in the ternary to 7.

    <umbraco:Macro Alias="Category2LeftNavigation" runat="server" startLevel="4" finishLevel="7"></umbraco:Macro>

  • Steve 472 posts 1216 karma points
    Aug 08, 2014 @ 21:18
    Steve
    0

    Here is my navigation Razor.

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{
    var StartLevel = String.IsNullOrEmpty(Parameter.startLevel) ? 4 : int.Parse(Parameter.startLevel);
    var FinishLevel = String.IsNullOrEmpty(Parameter.finishLevel) ? 6 : int.Parse(Parameter.finishLevel);
    var page = Model.AncestorOrSelf(StartLevel);
        if(page != null)
        {
        @traverse(page, StartLevel, FinishLevel);   
        }                
    }   
    
    @helper traverse(dynamic page, int StartLevel, int FinishLevel)
    {
        <ul class="nodeList">
            @foreach (var node in page.Children.Where("Visible && NodeTypeAlias == \"Category2InternalPage\" || NodeTypeAlias == \"ExternalLink\" || NodeTypeAlias == \"StudentGroupsPage\""))
                {
                var itemName = node.HasValue("shortPageTitle") ? @node.shortPageTitle : node.HasValue("pageTitle") ? @node.pageTitle : @node.pageName;
                var levelOne = node.IsAncestor(Model) ? "class=levelOne" : "";
                var childActive = node.IsEqual(Model) ? "class=activeChild" : "";
                var target = node.externalUrl ? "target=_blank" : "";
                var link = node.HasValue("externalUrl") ? node.url : node.Url;
                <li @childActive @levelOne ><a href="@link" @target>@itemName</a>
        @if(node.Children.Where("Visible && NodeTypeAlias == \"Category2InternalPage\" || NodeTypeAlias == \"ExternalLink\" || NodeTypeAlias == \"StudentGroupsPage\"").Count() > 0 && node.IsAncestorOrSelf(Model) && node.Level <= FinishLevel)
              { 
              @traverse(node, StartLevel, FinishLevel);
              }
                </li>
              }
        </ul>     
    }
  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Aug 08, 2014 @ 21:21
    Jeavon Leopold
    100

    Have you configured the parameter in the macro within the Umbraco UI also?

  • Steve 472 posts 1216 karma points
    Aug 08, 2014 @ 21:26
    Steve
    0

    Crud!! That was it! I thought for sure that I had added those to the macro. Sorry to waste your time Jeavon. Thanks for your help!

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Aug 08, 2014 @ 21:41
    Jeavon Leopold
    0

    No worries, I have certainly been there!

  • 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