#blocks that do not have link in CMS should not show link in frontend
1 messages · Page 1 of 1 (latest)
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 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
hi its Image media picker, i dont know how to add that thanks
this is where i want to implement logic, thanks in advance
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
i want to add this logic in that code: blocks that do not have link in CMS should not show link in frontend
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:
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
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
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.
AH duh, I was one step wrong.. I'm so used to already casting it the correct type 🙂
My bad