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 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.
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?
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. :(
:-( 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)
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.
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.
Get a True/False field into a macro parameter (Razor)
I have this 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.
I'm either getting errors that won't let me compare a boolean to ==, or having the whole thing just not work. Any tips?
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:
Thanks,
Jeavon
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.
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 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.
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):
In the cshtml file:
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]?
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?
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?
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. :(
:-( 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)
Hey Kurt, did you manage to resolve this issue?
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.
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.
is working on a reply...