It's been a while since I've had to write a Razor macro that uses a content picker as a property and I can't seem to get the syntax correct to get the url on the <a href>. Here is my code:
Thanks Dennis! This works great, except can I do this without a test for the value of contentPicker without risking exceptions? I really don't care if the user provides a url or not.
Okay, now I need to show you more of the code, because it says it's expecting a "}" after my first <a> line, but there is one right befor the "else". What's going on?
Well Dennis, I've done something like this, but if I add an <a> tag anywhere in any of the "featureBox" Content areas it creates another <a class="featureBox"> arround the link. Here is my code and the page: Page( https://edit-wwwprep.rose-hulman.edu/32742.aspx )
The big thing for me is correctly wrapping the featureBoxUrl, featureBoxImage, featureBoxHeadline and featureBoxContent all within the <a class="featureBox">, but for some reason, a user decides to put an in-line link within the "featureBoxContent" field on the page the razor doesn't wrap the outer <a> correctly, it in fact, ends it after the "featureBoxContent" field. Any suggestions about correcting this will be greatly appreaciated!!
Syntax for getting the URL Property of a Node
It's been a while since I've had to write a Razor macro that uses a content picker as a property and I can't seem to get the syntax correct to get the url on the <a href>. Here is my code:
Hi Steve,
Try to see this documentation on how to get the url from a content picker. https://our.umbraco.org/Documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/Content-Picker
An example.
Hope this helps,
/Dennis
Thanks Dennis! This works great, except can I do this without a test for the value of contentPicker without risking exceptions? I really don't care if the user provides a url or not.
Hi Steve,
You could give it a try just to use this. And then try not to add a link to one of the elements and see if you get any risking exceptions
Else then you could make an if else statement.
/Dennis
Looks like I will have to try the if/else because the macro fails to load without the if statement.
Okay, now I need to show you more of the code, because it says it's expecting a "}" after my first <a> line, but there is one right befor the "else". What's going on?
Hi Steve,
What if you do something like this would this work for you.
Hope this helps,
/Dennis
Well Dennis, I've done something like this, but if I add an <a> tag anywhere in any of the "featureBox" Content areas it creates another <a class="featureBox"> arround the link. Here is my code and the page: Page( https://edit-wwwprep.rose-hulman.edu/32742.aspx )
The big thing for me is correctly wrapping the featureBoxUrl, featureBoxImage, featureBoxHeadline and featureBoxContent all within the <a class="featureBox">, but for some reason, a user decides to put an in-line link within the "featureBoxContent" field on the page the razor doesn't wrap the outer <a> correctly, it in fact, ends it after the "featureBoxContent" field. Any suggestions about correcting this will be greatly appreaciated!!
is working on a reply...