Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Aditya.A 77 posts 96 karma points
    Aug 01, 2013 @ 10:37
    Aditya.A
    0

    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....

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 01, 2013 @ 10:48
    Dennis Aaen
    1

    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

  • Aditya.A 77 posts 96 karma points
    Aug 01, 2013 @ 11:02
    Aditya.A
    0

    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

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Aug 01, 2013 @ 11:03
    Sebastiaan Janssen
    1

    I think @Model.HasValue("videoId") will do null checks as well.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 01, 2013 @ 11:12
    Dennis Aaen
    2

    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

  • Aditya.A 77 posts 96 karma points
    Aug 01, 2013 @ 11:13
    Aditya.A
    0

    if so how can i hide the div ?? :)

  • Aditya.A 77 posts 96 karma points
    Aug 01, 2013 @ 11:16
    Aditya.A
    0

    <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

  • Aditya.A 77 posts 96 karma points
    Aug 01, 2013 @ 11:23
    Aditya.A
    0

    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>
    }

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 01, 2013 @ 11:23
    Dennis Aaen
    0

    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

  • Aditya.A 77 posts 96 karma points
    Aug 01, 2013 @ 11:32
    Aditya.A
    0

    I am still getting the error as if(True && 0koVbQBmV80!=String.Empty){

    The video is visible but this error is also comming...

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Aug 01, 2013 @ 11:33
    Sebastiaan Janssen
    2

    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>
    }
    
  • Aditya.A 77 posts 96 karma points
    Aug 01, 2013 @ 11:40
    Aditya.A
    0

    thank u for ur patience...but still

     

    if(Model.HasProperty("videoId") && Model.HasValue("videoId")) {

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Aug 01, 2013 @ 12:01
    Sebastiaan Janssen
    2

    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>
    }
    
  • Aditya.A 77 posts 96 karma points
    Aug 01, 2013 @ 12:04
    Aditya.A
    0

    awesome it works........thank u very much

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 01, 2013 @ 12:34
    Dennis Aaen
    2

    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

  • Aditya.A 77 posts 96 karma points
    Aug 01, 2013 @ 12:51
    Aditya.A
    0

    dont be sorry..u have saved my day..thank u once again..

Please Sign in or register to post replies

Write your reply to:

Draft