We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49667
    • 59 Posts


    I have a DIV like this for images I display with my articles:

    <div class="image">
    <img src="[*image*]">
    </div> 



    Now for my articles I can also have videos:

    <div class="well">
    <video width="400" controls>
     <source src="[*video*]" type="video/mp4">
      <source src="[*video*]" type="video/ogv">
    </video>
       </div> 


    Now the thing is that I have EITHER an image OR a video with my article, never both! But above code in my template reserves and shows space for both image and video always. So basically when I do not upload a video for a specific article (and thus only have an image), then the "space" for the video will show always like this...

    No video but space shows... image

    [/img][/img]

    When no image then the image space that shows... img2

    I do not want that it shows anything there and also not reserves the space for that DIV. The question is how to not have the "space" or the blank area when I do not use either [image] or [video]??

    I use MODx Evolution as my CMS.

    This question has been answered by ronbonqqq. See the first response.

      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You can either use a custom snippet to output the entire block if there is a value in the TV, or you can install and use phx, which does pretty much the same thing (is phx built in to the Evo core by now?).
      [*video:notempty=`<div class="well">
      <video width="400" controls>
       <source src="[*video*]" type="video/mp4">
        <source src="[*video*]" type="video/ogv">
      </video>
         </div>`*]
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 49667
        • 59 Posts
        Quote from: sottwell at Jul 13, 2015, 11:43 AM
        You can either use a custom snippet to output the entire block if there is a value in the TV, or you can install and use phx, which does pretty much the same thing (is phx built in to the Evo core by now?).
        [*video:notempty=`<div class="well">
        <video controls="" width="400">
         <source src="[*video*]" type="video/mp4">
          <source src="[*video*]" type="video/ogv">
        </video>
           </div>`*]

        No, Phx is not in core yet, but I downloaded it and tried your code... unfortunately I cannot get it to work... sad
        • discuss.answer
          • 49667
          • 59 Posts
          Got is solved with PHx and below code courtesy Zaigham (aka zi)and this post... https://forums.modx.com/thread/45312/phx---don-t-show-if-image-tv-is-empty

          [+phx:if=`[*tv_media*]`:ne=``:then=`<div class="well">
          <video controls="" width="400">
           <source src="[*tv_media*]" type="video/mp4">
            <source src="[*tv_media*]" type="video/ogv">
          </video></div>`+]
          		</div>


          Also thank you @sottwell for pointing the right direction to solve this... smiley
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            It's built-in to the Revo core as "output modifiers", and it usually takes me some time and several trials before I can get one to work right wink
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 9995
              • 1,613 Posts
              Most of the time I use this:

              [*tv_media:is=``:then=``:else=`
              <div class="well">
                <video controls="" width="400">
                  <source src="[*video*]" type="video/mp4">
                  <source src="[*video*]" type="video/ogv">
                </video>
              </div>
              `*]


              (You need PHx)
              There is also a default plugin called If.
              Somehow almost never use it.
                Evolution user, I like the back-end speed and simplicity smiley