Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
hello guys, i am using a below code in the marco to display a youtube video. the id is given by the user.
now i want to hide the div if no video is provided.
videoId is normal textstring in the document type.
@if(@Model.HasProperty("videoId")){
}
can any one help....
Hi Adity.A
Have you tried something like this
if(@Model.HasProperty("videoId") && @Model.GetProperty("videoId").Value!=String.Empty){ <iframe width="220" height="150" src="http://www.youtube.com/embed/@Model.GetPropertyValue("videoId")" frameborder="0" allowfullscreen></iframe>}
/Dennis
Hi,
Thank you for ur quick response..it will help in checking if the video value is empty or not
but how can i hide the div if the value is null .
the div name is as <div id="video_box"> </div>. it has a pink backgroud,so if the value of the video is null
this div should not be visible on page ..
can u suggest
I think @Model.HasValue("videoId") will do null checks as well.
where did the div been placed.
I think this should do the job. So the div video_box is only rendered if the videoId has a value.
if(@Model.HasProperty("videoId") && @Model.GetProperty("videoId").Value!=String.Empty){ <div id="video_box"> <iframe width="220" height="150" src="http://www.youtube.com/embed/@Model.GetPropertyValue("videoId")" frameborder="0" allowfullscreen> </iframe> </div>}
Maybe this could be the solution to you.
if so how can i hide the div ?? :)
<div id="video_box">
<ul>
<li class="new">
<umbraco:Macro Alias="Product_FeaturedReviewVideo_RZ" runat="server"></umbraco:Macro>
</div>
i insert the macro like this
if(True && 0koVbQBmV80!=String.Empty){
i am getting error like this for ur code
Okay then I think you should add this to your cshtml script file
if(@Model.HasProperty("videoId") && @Model.GetProperty("videoId").Value!=String.Empty){ <div id="video_box"> <ul> <li class="new"> <iframe width="220" height="150" src="http://www.youtube.com/embed/@Model.GetPropertyValue("videoId")" frameborder="0" allowfullscreen> </iframe> </li> </ul> </div>}
And the where this should be showing in the template just insert the macro like this. <umbraco:Macro Alias="Product_FeaturedReviewVideo_RZ" runat="server"></umbraco:Macro> So the cshtml file contains all the markup.
Hope this helps ;-)
I am still getting the error as if(True && 0koVbQBmV80!=String.Empty){
The video is visible but this error is also comming...
Remove the @ signs:
if(Model.HasProperty("videoId") && Model.GetProperty("videoId").Value != String.Empty) { <div id="video_box"> <ul> <li class="new"> <iframe width="220" height="150" src="http://www.youtube.com/embed/@Model.GetPropertyValue("videoId")" frameborder="0" allowfullscreen> </iframe> </li> </ul> </div> }
And I think this is a bit prettier:
if(Model.HasProperty("videoId") && Model.HasValue("videoId")) { <div id="video_box"> <ul> <li class="new"> <iframe width="220" height="150" src="http://www.youtube.com/embed/@Model.GetPropertyValue("videoId")" frameborder="0" allowfullscreen> </iframe> </li> </ul> </div> }
thank u for ur patience...but still
if(Model.HasProperty("videoId") && Model.HasValue("videoId")) {
How about @if?
@if(Model.HasProperty("videoId") && Model.HasValue("videoId")) { <div id="video_box"> <ul> <li class="new"> <iframe width="220" height="150" src="http://www.youtube.com/embed/@Model.VideoId" frameborder="0" allowfullscreen> </iframe> </li> </ul> </div> }
awesome it works........thank u very much
Oh I see that the editor has eaten my first @ sign for the if block, when I made some corrections in my post.Sorry for the missing @ sign.
dont be sorry..u have saved my day..thank u once again..
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Hide a div when there is no video
hello guys, i am using a below code in the marco to display a youtube video. the id is given by the user.
now i want to hide the div if no video is provided.
videoId is normal textstring in the document type.
@if(@Model.HasProperty("videoId")){
}
can any one help....
Hi Adity.A
Have you tried something like this
if(@Model.HasProperty("videoId") && @Model.GetProperty("videoId").Value!=String.Empty){
<iframe width="220" height="150"
src="http://www.youtube.com/embed/@Model.GetPropertyValue("videoId")"
frameborder="0" allowfullscreen></iframe>
}
/Dennis
Hi,
Thank you for ur quick response..it will help in checking if the video value is empty or not
but how can i hide the div if the value is null .
the div name is as <div id="video_box"> </div>. it has a pink backgroud,so if the value of the video is null
this div should not be visible on page ..
can u suggest
I think @Model.HasValue("videoId") will do null checks as well.
where did the div been placed.
I think this should do the job. So the div video_box is only rendered if the videoId has a value.
if(@Model.HasProperty("videoId") && @Model.GetProperty("videoId").Value!=String.Empty){
<div id="video_box">
<iframe width="220" height="150"
src="http://www.youtube.com/embed/@Model.GetPropertyValue("videoId")"
frameborder="0" allowfullscreen>
</iframe>
</div>
}
Maybe this could be the solution to you.
/Dennis
if so how can i hide the div ?? :)
<div id="video_box">
<ul>
<li class="new">
<umbraco:Macro Alias="Product_FeaturedReviewVideo_RZ" runat="server"></umbraco:Macro>
</div>
i insert the macro like this
if(True && 0koVbQBmV80!=String.Empty){
i am getting error like this for ur code
if(@Model.HasProperty("videoId") && @Model.GetProperty("videoId").Value!=String.Empty){
<div id="video_box">
<iframe width="220" height="150"
src="http://www.youtube.com/embed/@Model.GetPropertyValue("videoId")"
frameborder="0" allowfullscreen>
</iframe>
</div>
}
Okay then I think you should add this to your cshtml script file
if(@Model.HasProperty("videoId") && @Model.GetProperty("videoId").Value!=String.Empty){
<div id="video_box">
<ul>
<li class="new">
<iframe width="220" height="150"
src="http://www.youtube.com/embed/@Model.GetPropertyValue("videoId")"
frameborder="0" allowfullscreen>
</iframe>
</li>
</ul>
</div>
}
And the where this should be showing in the template just insert the macro like this. <umbraco:Macro Alias="Product_FeaturedReviewVideo_RZ" runat="server"></umbraco:Macro> So the cshtml file contains all the markup.
Hope this helps ;-)
/Dennis
I am still getting the error as if(True && 0koVbQBmV80!=String.Empty){
The video is visible but this error is also comming...
Remove the @ signs:
And I think this is a bit prettier:
thank u for ur patience...but still
if(Model.HasProperty("videoId") && Model.HasValue("videoId")) {
How about @if?
awesome it works........thank u very much
Oh I see that the editor has eaten my first @ sign for the if block, when I made some corrections in my post.
Sorry for the missing @ sign.
/Dennis
dont be sorry..u have saved my day..thank u once again..
is working on a reply...