Copied to clipboard

Flag this post as spam?

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


  • Kurt Emch 44 posts 85 karma points
    Jun 05, 2013 @ 00:03
    Kurt Emch
    0

    Get a True/False field into a macro parameter (Razor)

    I have this macro:

    <umbraco:Macro showSubnavChildren="[$pageShowSubnavChildren]" runat="server"></umbraco:Macro>

    The field, pageShowSubnavChildren in my document type is a True/False data type.

    In the macro itself, I'd like to display some extra HTML if the pageShowSubnavChildren is set to true.

    var showChildren = @Parameter.showSubnavChildren;
    @if (showChildren == true) { ... }

    I'm either getting errors that won't let me compare a boolean to ==, or having the whole thing just not work. Any tips?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 05, 2013 @ 10:16
    Jeavon Leopold
    0

    Hi Kurt,

    Unfortunately macro parameters are not automatically type converted when returned in parameters unlike when you access a property using @Model.showSubnavChildren, instead they are always a string.

    I would use something like this to test the string:

    @{
        var showChildren = Parameter.showSubnavChildren;    
        if (showChildren.Equals("1")){
            <p>true</p>    
        }else{
            <p>false</p>
        } 
    }

    Thanks,

    Jeavon

  • Kurt Emch 44 posts 85 karma points
    Jun 05, 2013 @ 16:01
    Kurt Emch
    0

    Thanks for the reply. That seems like it should work, but it isn't. I'm wondering if I have something set up wrong. If I render the contents of that variable, I get nothing. No errors either.

    var showChildren = @Parameter.showSubnavChildren;

    I even went as far as setting the field in the doc type to a text string, and trying to get it out like this.

    @if (showChildren.Equals("ShowChildren")){
      <h1>It is 1 @showChildren</h1>
      } else if (showChildren.Equals("HideChildren")) {
      <h1>It is 0 @showChildren</h1>
      } else {
      <h1>It is none.</h1>
    }

    If I set its the textstring field to "ShowChildren" in the content editor, I get "It is none.".

    I have another parameter going into this same macro, so I'm baffled as to why it isn't working. 

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 05, 2013 @ 16:42
    Jeavon Leopold
    0

    Hmm, I can't understand the problem.... What version of Umbraco are you using (may be it's a fixed bug)?

    Here's what I have tested as working, the macro call in the template (umbracoNaviHide is a true/false):

     <umbraco:Macro showSubnavChildren="[$umbracoNaviHide]" Alias="[RAZOR]TrueFalse" runat="server"></umbraco:Macro>

    In the cshtml file:

     @{
        var showChildren = Parameter.showSubnavChildren;
        if (showChildren.Equals("1")){
            <p>true</p>    
        }else{
            <p>false</p>
        } 
    }
  • Kurt Emch 44 posts 85 karma points
    Jun 05, 2013 @ 17:24
    Kurt Emch
    0

    Thanks Jeavon. I have version 6.05. I can only get your example to return false. Here's my Macro. Question, why is your Alias prepended with [RAZOR]?

    <umbraco:Macro
    sectionId="[$pageSection],1048"
    showSubnavChildren="[$pageShowSubnavChildren]"
    Alias="PageSubnav"
    runat="server">
    </umbraco:Macro>

    Here's the field in my document type:
    http://cl.ly/image/1x3B382I202R

    And the parameters in I put in my Macro:
    http://cl.ly/image/0G1B3S1u2F2n

    That's all about right, correct?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 05, 2013 @ 18:00
    Jeavon Leopold
    0

    All looks perfect and I've tried on v6.0.5 so it's not a bug. I am wondering if maybe it is something to do with the $ recursive page value, does the page you are testing on have the pageShowSubnavChildren property or only it's parent?

  • Kurt Emch 44 posts 85 karma points
    Jun 05, 2013 @ 18:44
    Kurt Emch
    0

    I have the field as part of a Master Document Type, of which my Page Document Type is a child of. The content node I am testing with, in this case the 'Our Company' page, I have checked the box to Yes (true). And it returns false. :(

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 05, 2013 @ 19:27
    Jeavon Leopold
    0

    :-( It's really odd, all seems fine! Below is a link to download the test site I created to test this issue, maybe you could take a look to see it you can see anything different? https://dl.dropboxusercontent.com/u/14453377/TrueFalse.zip (username and password are both admin)

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 06, 2013 @ 20:04
    Jeavon Leopold
    0

    Hey Kurt, did you manage to resolve this issue?

  • Kurt Emch 44 posts 85 karma points
    Jun 06, 2013 @ 22:58
    Kurt Emch
    0

    Hi Jeavon, not yet. My project seemed to be identical to yours, so I'm not sure what the problem. I'm going to take a break from it, and come back to it with fresh eyes next week.

    I'm starting to notice that when fields are deleted in the document type but are still being called to render in a template still show up. I don't know if that's a feature, or intended. I had created and deleted some of these fields several times, so maybe it's just getting mixed up somewhere. I don't know if this would be the problem or not, but it sometimes yields strange results as I work.

    Thanks for all your help with this. I'll post back where I end up with it.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 07, 2013 @ 10:11
    Jeavon Leopold
    0
    Hi Kurt,

    That is a very annoying one. If you want to be absolutely sure that a site cache is fully cleared, follow these steps:

    1.Stop App Pool
    2.Delete App_Data/umbraco.config
    3.Delete all folders inside App_Data/Temp/ExamineIndexes
    4.Delete all files inside App_Data/Temp/ClientDependancy
    5.Start the App Pool

    Jeavon
  • Kurt Emch 44 posts 85 karma points
    Jun 08, 2013 @ 03:07
    Kurt Emch
    0

    It is! Thanks I'm going to try this next week. I recall deleting those files worked for me in another instance. Crossing my fingers – I'll keep you updated. Thanks a bunch.

Please Sign in or register to post replies

Write your reply to:

Draft