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

    I have a TV [+hotelPrice+] input type: text, and a SNIPPET [+priceDollars+].

    The idea is, the client fill the TV and the snippet display a small HTML code that include the TV content, a price in this case, if the TV is empty, the HTML is not displayed!

    Works Sweet!!!!! laugh (use it if you need it)

    Snippet:
    <?php
    // parameters:
    // &tvname - Set the TV name to be used, defaults to hotelPrice
    $TVname = isset($TVname)?$TVname:'hotelPrice';
     
    // fetch the output array of the TV
    if( $TVarray = $modx->getTemplateVarOutput(array($TVname)) ){
    	#TV output is in index [$TVname][1]
    	$tvOutput = $TVarray[$TVname][1];
    	if(empty($tvOutput)) return ''; //bail out if no value
     
    	// Here is where we can start customizing the output.
    	// For now, just return the TV output in a <div> container
    	return '<div><p>Price from:</p>
                              <p>$[*hotelPrice*]</p>
    		  </div>';
    }
    return '';
    ?>
    


    THE PROBLEM!!!

    I need to do the seem thing (display and hide) the HTML code with the TV information in it!
    Called with a DITTO, but IS NOT WORKING!!!

    HELLLLPPPPPPPPP!!!!!!!!!!!!!!!!!!
    here the codes:

    Ditto Call:
    [!Ditto? &parents=`53` &display=`all` &total=`all` &showInMenuOnly=`0` &orderBy=`menuindex ASC` &extenders=`summary` &randomize=`0` &tpl=`nl_sidebar_activities`&filter=`id,139,2` !]
    


    Ditto Chunk:
    <div id="packagesTextAct">
         [[priceDollarsList]]
         <a class="bookingSmall" href="[~218~]&formTitle=[+pagetitle+]" title="[+longtitle+]">See more</a>
    </div>
    


    I hope you understand!!!

    Please some programer or someone with full ModX knowledge may be perfect!!!
    i.m using:
    ModX Evo 1.0.6
    Ditto 2.1.0

    Thank you Very Much!!!!
      --
      ysanmiguel.com
      • 33238
      • 388 Posts
      Ahhh!!! I try call the ditto and the TV and the snippet cached/uncached and nothing happens!!! :S
        --
        ysanmiguel.com
        • 19369
        • 1,098 Posts
        Usually I check if a TV is empty or not with PHx:
        http://wiki.modxcms.com/index.php/PHx#Advanced_usage
          • 16278
          • 928 Posts
          Your call to getTemplateVarOutput() is going to need a reference to each document's ID, I should think. You could pass it from the chunk as a parameter to the snippet call:
          (untested)

          <div id="packagesTextAct">
               [[priceDollarsList?docid=`[+id+]`]]
               <a class="bookingSmall" href="[~218~]&formTitle=[+pagetitle+]" title="[+longtitle+]">See more</a>
          </div>
          


          and use it in the snippet
          ...
          $docid = isset($docId) ? $docid : $modx->documentIdentifier;
          ...
          if( $TVarray = $modx->getTemplateVarOutput(array($TVname), $docid) ){
          ...
          


          :) KP
            • 33238
            • 388 Posts
            Hello KP!!!

            my friend still not working...

            if i call the snippet (unchacheable) i can see the ID of every doc, but uncacheable the snippet is not running!

            but the TV content is not displayed!

            i think the problem may be in the snippet code, but i don't have idea if I'm putting your code in the right place!

            check this please!

            thank you!

            <?php
            $tvname = isset($TVname)?$TVname:'hotelPrice';
            
            $docid = isset($docId) ? $docid : $modx->documentIdentifier;
            if( $TVarray = $modx->getTemplateVarOutput(array($TVname), $docid) ){
            
            	#TV output is in index [$TVname][1]
            	$tvOutput = $TVarray[$TVname][1];
            	if(empty($tvOutput)) return ''; //bail out if no value
             
            	// Here is where we can start customizing the output.
            	// For now, just return the TV output in a <div> container
            	return '<div id="packagesPrice">
                    				<p>Price From:</p>
                    				<div id="hotelsPriceNumb">
                            				<p>$[+hotelPrice+]</p>
                            		</div>
                    		</div>';
            }
            return '';
            ?>
            
              --
              ysanmiguel.com
              • 33238
              • 388 Posts
              microcipcip

              Have you tried PHx from Ditto?
              i need to know to spend time trying to use this in my project!

              anyway, thank you very much for the advice!!!
                --
                ysanmiguel.com
                • 19369
                • 1,098 Posts
                I always use PHx inside ditto without any issue.
                  • 33238
                  • 388 Posts
                  Thank you man! i will try it!!! laugh
                    --
                    ysanmiguel.com
                    • 16278
                    • 928 Posts
                    Sorry, I edited the variable name $docId to $docid for consistency with the API docs - but left one instance with the old name, so it wouldn't work. Line 4 should read:
                    $docid = isset($docid) ? $docid : $modx->documentIdentifier;

                    I usually try to test out code before posting it, hence the "untested".

                    PHx works fine within Ditto, but Ditto will sometimes fail to retrieve the value of a TV without a little help. I suggest you try to get your snippet working first.

                    :) KP
                      • 33238
                      • 388 Posts
                      KP. not working my friend!!!
                      the snippet call uncached [! display the info ID and TV content.
                      but the snippet is not running!!

                      if you have other suggestion that may be perfect!!! laugh

                      anyway i will try PHx and i will let you know what happen, i hope works! this is so frustrating!!! :S

                      thank you all!
                        --
                        ysanmiguel.com