We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15914
    • 145 Posts
    I think I’ve spotted bug.

    When you insert an Image TV Widget and the TV is left blank by the editor of the document, it still outputs the IMG tag on the page; just with an empty SRC attribute. Surely if the TV is empty, it wouldn’t display the IMG tag at all?

    I created a snippet which checks if the TV is empty and if it is, not to return the TV Output of the Widget. So instead of calling the TV, I call this snippet in my template:

    //$tv_image is the TV that contains the Image Widget.
    // has $tv_image been defined? If not, default to contentImage.
    if( !$tv_image ) { $tv_image = "contentImage"; }
    
    // fetch the src for the image to be used in the content.
    $tv = $modx->getTemplateVar($tv_image);
    $src = $tv['value'];
    
    // if there is an image selected, find and return the output of the TV.
    if ($src) {
    
      // fetch the document's current id.
      $currentid = $modx->documentObject['id'];
    
      // fetch the TV output and store it in $output.
      $value = $modx->getTemplateVarOutput($tv_image, $currentid);
      $output = $value[$tv_image];
    
      // return
      return $output;
    
    }


    That was my quick temporary solution.
      Kunal Kapoor
      Technical Director
      Limesharp Internet Limited - Effective, Functional, Standards Compliant

      IRC Nick: KingKoopa
      Skype ID: KingKoopa16
      • 15914
      • 145 Posts
      Should I put this in the bugtracker?
        Kunal Kapoor
        Technical Director
        Limesharp Internet Limited - Effective, Functional, Standards Compliant

        IRC Nick: KingKoopa
        Skype ID: KingKoopa16
      • Yes, please. smiley
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 15914
          • 145 Posts
            Kunal Kapoor
            Technical Director
            Limesharp Internet Limited - Effective, Functional, Standards Compliant

            IRC Nick: KingKoopa
            Skype ID: KingKoopa16
            • 7455
            • 2,204 Posts
            I had the same problem I just placed a spacer.gif in it so it works (displaying a 1 pixel nothing)
              follow me on twitter: @dimmy01
              • 29635
              • 361 Posts
              The Man Can! Reply #6, 18 years ago
              Thanks for that snippet, Kunal. The HTML Generic Tag widget has the same problem, so I did a quick recode of your snippet so that it’d be apparent that it works for both widgets. (I just changed the variable names, I think, and added a little documentation. I hope that’s OK with you.)

              // *********************************************
              // SNIPPET:            TV
              // Version:            1.0
              // By:                 Kunal Kapoor
              // Slight mods by:     Brett at The Man Can!
              // *********************************************
              //
              // USAGE:
              // The image widget and the HTML Generic Tag
              // widgets return output even if the TV value
              // is empty. Use this snippet to call a TV
              // instead of calling the TV directly, in order
              // to avoid having empty DIVs and IMG tags.
              //
              // DETAILS:
              // http://modxcms.com/forums/index.php/topic,2940.0.html
              //
              // OPTIONS:
              // name        The name of the TV that you're calling.
              //
              // EXAMPLE:
              // Call        [!TV? &name=`colR` !]
              // instead of  [*colR*]
              //
              // *********************************************
              
              // Do not modify below.
              
              // $name is the TV that contains the Widget.
              // Has $name been defined? If not, return nothing.
              if( !$name ) { return ''; }
              
              // fetch the src for the TV to be used in the content.
              $tv_source = $modx->getTemplateVar($name);
              $src = $tv_source['value'];
              
              // if there is an image selected, find and return the output of the TV.
              if ($src) {
              
                // fetch the document's current id.
                $currentid = $modx->documentObject['id'];
              
                // fetch the TV output and store it in $output.
                $value = $modx->getTemplateVarOutput($name, $currentid);
                $output = $value[$name];
              
                // return
                return $output;
              
              }
              


              Hopefully that helps somebody.
              Thanks again Kunal for the original.
              -Brett
                Need MODx Ecommerce? Try FoxyCart!
                • 17883
                • 1,039 Posts
                Brett and Kunal, this is very handy! In the core distritbution should empty values be better handled.
                  • 15914
                  • 145 Posts
                  Quote from: The at May 06, 2006, 07:11 PM
                  (I hope that’s OK with you.)
                  ...
                  Thanks again Kunal for the original.

                  You’re welcome. Of course it’s OK. smiley Great work Brett.
                    Kunal Kapoor
                    Technical Director
                    Limesharp Internet Limited - Effective, Functional, Standards Compliant

                    IRC Nick: KingKoopa
                    Skype ID: KingKoopa16
                    • 1549
                    • 20 Posts
                    Quote from: The at May 06, 2006, 07:11 PM

                    Thanks for that snippet, Kunal. The HTML Generic Tag widget has the same problem, so I did a quick recode of your snippet so that it’d be apparent that it works for both widgets. (I just changed the variable names, I think, and added a little documentation. I hope that’s OK with you.)

                    // *********************************************
                    // SNIPPET:            TV
                    // Version:            1.0
                    // By:                 Kunal Kapoor
                    // Slight mods by:     Brett at The Man Can!
                    // *********************************************
                    //
                    // USAGE:
                    // The image widget and the HTML Generic Tag
                    // widgets return output even if the TV value
                    // is empty. Use this snippet to call a TV
                    // instead of calling the TV directly, in order
                    // to avoid having empty DIVs and IMG tags.
                    //
                    // DETAILS:
                    // http://modxcms.com/forums/index.php/topic,2940.0.html
                    //
                    // OPTIONS:
                    // name        The name of the TV that you're calling.
                    //
                    // EXAMPLE:
                    // Call        [!TV? &name=`colR` !]
                    // instead of  [*colR*]
                    //
                    // *********************************************
                    
                    // Do not modify below.
                    
                    // $name is the TV that contains the Widget.
                    // Has $name been defined? If not, return nothing.
                    if( !$name ) { return ''; }
                    
                    // fetch the src for the TV to be used in the content.
                    $tv_source = $modx->getTemplateVar($name);
                    $src = $tv_source['value'];
                    
                    // if there is an image selected, find and return the output of the TV.
                    if ($src) {
                    
                      // fetch the document's current id.
                      $currentid = $modx->documentObject['id'];
                    
                      // fetch the TV output and store it in $output.
                      $value = $modx->getTemplateVarOutput($name, $currentid);
                      $output = $value[$name];
                    
                      // return
                      return $output;
                    
                    }
                    


                    Hopefully that helps somebody.
                    Thanks again Kunal for the original.
                    -Brett

                    Good idea, but how to use it with ditto and empty img tags. In ditto, when assigning a TV it has to have a [+tvNAMEOFTV+]... I tried every combination like [!TV? &name=`[+tvmyownimagetv+]`!] and [!TV? &name=`myownimagetv`!] and [!TV? &name=`tvmyownimagetv`!] , but it doesn’t work.
                      • 6726
                      • 7,075 Posts
                      How did I miss that thread ?!
                      I didn’t know a fix existed sad

                      Now I do... We definitely have to make sure this get properly adressed for the next release...
                        .: COO - Commerce Guys - Community Driven Innovation :.


                        MODx est l'outil id