Copied to clipboard

Flag this post as spam?

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


  • Stephen 94 posts 255 karma points
    Apr 17, 2013 @ 16:17
    Stephen
    0

    Fixed value for Document Types

    Hi All,

    Now I am assuming I am being thick here.  I have tried a few things, and can't get this to work for me.

    Basically I have document types that I don't want shown on the menu.

    My current very simple solution is a True/False tick box with an Alias of "umbracoNaviHide", whcih works fine so long as you tick it.

    Obviously for items that I never want to show in the menu it would make sence to me to have a fixed value that I can add, instead of having to tick something.  In other words have something with an alias of "umbracoNavHide" permanently set to true (or I think 1 would be the same thing).

    I have played with an "Noedit" data type, but I really just don't get how this one actually works.  I have read quite a bit about it, but it's not doing what I need, or possibly more realistically I am not doing it properly.

    Perhaps there is a much simple way of doing this and I am just not seeing it.  Any help much appreciated.

    Thanks

    Stephen

  • Rich Green 2246 posts 4008 karma points
    Apr 17, 2013 @ 16:43
    Rich Green
    0

    Hey Stephen,

    We actually do it the other way around, we add a 'showInMainNavigation' True/False property and only items which have this set to true get shown.

    Rich

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Apr 17, 2013 @ 16:57
    Hendy Racher
    0

    (@Rich yeah, makes much more sense when true means something is enabled - or do something)

  • Stephen 94 posts 255 karma points
    Apr 17, 2013 @ 17:35
    Stephen
    0

    Hi Guys,

    Thanks for the comments, That does kinda make sence, but one immediate thought, umbracoNaviHide is an actual Umbraco supported property, is "showInMainNavigation", as a quick websearch didn't reveal anything.  umbracoNaviHide is detailed in the Best Practice part of the website (http://our.umbraco.org/wiki/reference/umbraco-best-practices/umbraconavihide).

    Either way I am thinking of my less web savy customer who find doing anything with a website really stressful, and when things don't appear or appear when they should not getting even more stressed.

    So my question still stands if I want something to never or always be shown is there a way to add a fixed value to a document type?  Even a way to set the default value of a tick box to ticked?

    Thanks

    Stephen

  • Rich Green 2246 posts 4008 karma points
    Apr 17, 2013 @ 17:40
    Rich Green
    0

    Hey Stephen,

    You're right, umbracoNaviHide is a convention, it's a convention for hiding something, going back it used to part of an install, it no longer is, the reason it gets used is some of the sample scripts use it.

    What you're trying to do is counter intuative, but try the Standard Values Package http://our.umbraco.org/projects/developer-tools/standard-values-in-umbraco

    Rich

     

  • Stephen 94 posts 255 karma points
    Apr 17, 2013 @ 17:47
    Stephen
    0

    Hi Rich,

    Thanks for your reply.

    Could you please explain "counter intuative" (not the meaning of the words, but how what I want to do is counter intuative).  I am not being defensive, if I am not using best practice, or there is a better way then, that's what I want to do.  I just want it to be as simple for my customers as possible to use the interface.  It seems right to me if something should always be displayed then why have it go to tick it to be displayed, or if it should not be displayed, why should I have to tick it not to be displayed?  What am I missing here?

    I am off to look at standard-values-in-umbraco.

    Thanks

    Stephen

  • Rich Green 2246 posts 4008 karma points
    Apr 17, 2013 @ 17:51
    Rich Green
    0

    Maybe counter intuative is the wrong expression.

    If you don't want a DocType to ever display on the menu then just ensure they don't in your XSLT / Razor script, you don't have to set a checkbox to true on every node of that DocType.

    Rich

  • Stephen 94 posts 255 karma points
    Apr 17, 2013 @ 18:20
    Stephen
    0

    Hi Rich,

    Doesn't that mean that I have to check every DocType, which on bigger sites could be up to 10 or more different types (which is a lot to check), hence a single value for show or not show makes sence to me.  Am I being thick here?  I don't mind if the answer is yes, I just seem to be missing the point?

    Lets assume that my site will have:

    To be displayed:

    Standard page

    Contact page

    Enquiry form

    Twio column page

    Not to be displayed (on menu)

    News article

    Case study

    Staff member

    So there are a number of different DocTypes the either need to eb displayed or not.  So to check for  number of DocTypes seems messy to me.

    Thanks

    Stephen

  • Rich Green 2246 posts 4008 karma points
    Apr 17, 2013 @ 18:28
    Rich Green
    0

    Hey Stephen,

    There are many different ways to do this, it's personal preference.

    You don't have to check 10 DocTypes, your script can just exclude the DocTypes you don't want on the menu. It's all done via cached XML so performance won't be any issue.

    Rich

  • Stephen 94 posts 255 karma points
    Apr 17, 2013 @ 18:48
    Stephen
    0

    Hi Rich,

    Thanks for all your comments.

    I like the idea of using XML to exclude.

    Obviously I have no idea how to do this, do you know of any example for razor?

    I did check before I asked, I have done a number of searches, I am just not 100% sure what to search for.

    Thanks

    Stephen

  • Rich Green 2246 posts 4008 karma points
    Apr 17, 2013 @ 18:52
    Rich Green
    0

    Hey Stephen,

    Can you post the Razor you are using?

    Rich

  • Stephen 94 posts 255 karma points
    Apr 17, 2013 @ 19:19
    Stephen
    0

    Hi Rich,

    Sure this is what I am currently using.

    @{ 
    var ulClass = String.IsNullOrEmpty(Parameter.UlClass) ? "" : String.Format(" class=\"{0}\"", Parameter.UlClass); 
      var startLevel = 1;
      var finishLevel = 3;   
      var parent = @Model.AncestorOrSelf(startLevel);
      if (parent != null) { @ulMenu(parent, startLevel, finishLevel) ; }
    }
     
    @helper ulMenu(dynamic parent, int startLevel, int finishLevel)
    {
    <ul id="menu">
    @foreach (var node in parent.Children.Where("Visible")) {
            <li>
                <a href="@node.Url">@node.Name</a>                                       
                @if (@node.Level <= finishLevel) { @ulMenuSub(node, startLevel, finishLevel); }  
            </li>
        }
     </ul>              
    }
     
    @helper ulMenuSub(dynamic parent, int startLevel, int finishLevel)
    {
    if (@parent.Children.Where("Visible").Count() !=0){
    var clsString = "subTopMenu" + parent.Id;
    <ul class="@clsString">
    @foreach (var node in parent.Children.Where("Visible")) {
            <li>
                <a href="@node.Url">@node.Name</a>                                       
                @if (@node.Level <= finishLevel) { @ulMenuSub(node, startLevel, finishLevel); }  
            </li>
        }
     </ul>  
    }
    }
     

     

    The second version of the sub is just me being lazy, add different classes and ID to the ULs.

    This code just renders a 3 level menu, where the umbracoNaviHide is set to false.

    Thanks

    Stephen

  • Stephen 94 posts 255 karma points
    Apr 18, 2013 @ 13:21
    Stephen
    100

    Hi Rich,

    I guess this is the type of thing you are talking about, I modified ulMenu to include this:

    var values = new Dictionary<string,object>();
    var menuNodeTypes = new List<string>();
    menuNodeTypes.Add("BlankPage");
    menuNodeTypes.Add("dog");
    menuNodeTypes.Add("fish");
    values.Add("menuNodeTypes",menuNodeTypes);
    <ul id="menu">
    <li><a href="/">Home</a></li>
    @foreach (var node in parent.Children.Where("Visible && NodeTypeAlias.ContainsAny(menuNodeTypes)", values)) {

    After reading a number of other posts etc, I found most of this info covered in The Razor Feature Walkthrough.

    If you had something else in mind, would be good if you could share.

    But this essentially fixes my problem two fold.

    I can still opt to hide items from the menu.

    Only certain types of DocType will be displayed in the menu (those listed with their name in full in the "Dictionary".

    Anyway hope this helps someone else too.

    Thanks

    Stephen

  • Rich Green 2246 posts 4008 karma points
    Apr 18, 2013 @ 13:44
    Rich Green
    0

    Hey Stephen,

    Sorry I didn't get the time to come back with a code sample, seems like you solved it anyways :)

    Looks like an more elegent solution than your original one, nice work

    Rich

  • Stephen 94 posts 255 karma points
    Apr 18, 2013 @ 16:55
    Stephen
    0

    Thanks.

    All that reading helps me to learn and improve anyway.  So all good.

    Thanks for all your help, I would not have got to where I am without it.

    Stephen

Please Sign in or register to post replies

Write your reply to:

Draft