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);
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);
There is nothing wrong with this. Are you sure that
Parameter.startLevelis the correct parameter alias and has a value?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>
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> }Have you configured the parameter in the macro within the Umbraco UI also?
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!
No worries, I have certainly been there!
is working on a reply...
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.