blocks that do not have link in CMS should not sho...
# help-with-umbraco
a
You're seem to be using the Url() property on your BlockList Item
oh wait, you have a propety called 'Url' added to it ? So thats why you check for content.Url ?
Is the Url a linkpicker? If so, then you probably should check on
Copy code
content.Url.Url()
as content.Url properly returns the type always, hence it always triggers the first option in your if/else
You could test if you type
@content.Url
in front of your if/else, then you'll see what is being checked
b
hi its Image media picker, i dont know how to add that thanks
this is where i want to implement logic, thanks in advance
a
Have you tried printing the value the
content.Url
returns? I guess its a mediapickerproperty then, Try
content.Url.Url()
As you named the mediapicker
Url
and you need the
Url()
property of your media item
b
i want to add this logic in that code: blocks that do not have link in CMS should not show link in frontend
a
yes
But you need to knowe what content.Url is currently, I THINK its a mediapicker(it looks like it), So i THINK it should work if you change your first attempt, (the one with the if/else), to:
Copy code
csharp
if(string.isNullOrWhiteSpace(content.Url.Url()))
it might work
however, I would not advice to name your MediaPicker 'Url', as it's not only the Url thats returned, but an entire Media object. I'd recommend to naming it something like 'image' for easier usage
b
im using blocklist content and i want blocks that do not have link in CMS should not show link in frontend
its using single url picker as property editor , my bad
d
Your content is of type
IPublishedElement
, it doesn't have a url property. You need to use the weakly typed method
.Value<>()
to get the property value that you need or add a type check to your logic.
a
AH duh, I was one step wrong.. I'm so used to already casting it the correct type 🙂 My bad
b
where should i implement this , im confused
2 Views