We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2178
    • 7 Posts
    echo 'You have entered: '.htmlentities($color);


    Just want to clarify, I’m pretty sure that you want to use:

    return 'You have entered: '.htmlentities($color);


    Or better yet:

    $message = 'You have entered: '.htmlentities($color);
    return $message;


    I’m still a MODx newb, but I believe the documentation recommends using ’return’ instead of ’echo’.
      • 45946
      • 4 Posts
      I have tried the solutions listed in this string, but it's not working and I can't figure out where I'm going wrong. Can someone please give me some insight/advice? I'm using MODx Evo 1.0.12, trying to pass plain text string of city name via template variable to a snippet. It's displaying the snippet with all the parameters set except for the one I'm sending via the TV. So, at least I know the snippet and call from the resource is working.

      The goal is to get a geo-specific return of info from the snippet, to display in the content portion of the page. On the Resource page's content, I have:
      [!reviews? &city=`[*cityTV*]`!]

      The template variable name is cityTV, input type is text, no default value (tried it with Atlanta default value, but that didn't change anything).

      The snippet is named reviews. Here's what I have as the snippet PHP, using bold to highlight the param I'm trying to pass via TV:
      <?php
      $agent = urlencode($_SERVER['HTTP_USER_AGENT']);
      $state = "GA";
      $city = "";
      $radius = "5";
      $showMap = "yes";
      $showFavorites = "";
      $techEmail = "";
      $reviewStart = "1";
      $checkinStart = "1";
      $reviewCount = "25";
      $checkinCount = "15";
      $zoom = "11";
      $reviewCityUrl = "";
      $mapSize = "medium";
      $mapScrollWheel = "yes";
      $fbLike = "";
      $fbComment = "";
      $token = "clienttokennumber";
      $url = "http://api.site.com/plugin/vendorstring";
      $response = file_get_contents($url);
      echo $response;
      ?>

      If I set the $city in the PHP, it populates the return from the plugin in the heading string but doesn't filter the reviews displayed. If I set type just the city name (e.g., Cartersville) without any enclosing marks or spaces in the TV field, I'm seeing no effect...

      What am I doing wrong?

      Thanks,
      Rinnie
      • Looks like you need to actually use the &city property, something like this:
        $city = isset($city) ? $city : '';
          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
          • 4041
          • 788 Posts
          If Susans method doesn't work maybe try this:
          snippet call:

          [!reviews? &city=`cityTV`!]


          snippet code:
          $agent = urlencode($_SERVER['HTTP_USER_AGENT']);
          $state = "GA";
          $base_city = isset( $city ) ? $city : "";
          $city_tv = $modx->getTemplateVarOutput( array( $base_city ) );
          $city = $city_tv[$base_city];
          $radius = "5";
          $showMap = "yes";
          $showFavorites = "";
          $techEmail = "";
          $reviewStart = "1";
          $checkinStart = "1";
          $reviewCount = "25";
          $checkinCount = "15";
          $zoom = "11";
          $reviewCityUrl = "";
          $mapSize = "medium";
          $mapScrollWheel = "yes";
          $fbLike = "";
          $fbComment = "";
          $token = "clienttokennumber";
          $url = "http://api.site.com/plugin/vendorstring";
          $response = file_get_contents($url);
          return $response;
            xforum
            http://frsbuilders.net (under construction) forum for evolution
            • 45946
            • 4 Posts
            Wow, that was fast! Thanks so much for the responses, you two!

            Those two ideas didn't quite get it working yet...

            Adding the lines
            $base_city = isset( $city ) ? $city : "";
            $city_tv = $modx->getTemplateVarOutput( array( $base_city ) );
            $city = $city_tv[$base_city];

            ...to the PHP instead of
            $city = "";

            ...returns an SQL syntax error. So, I think the plugin is finicky.

            I did try setting the $city directly in the PHP, leaving the TV empty, and it worked...but only when I did it as
            $city = urlencode('Stone Mountain');


            So, I changed the TV definition via the field for cityTV at the bottom of the Resource Page to the part between the = and the ;
            urlencode('Stone Mountain')


            But it still isn't working. I tried calling the snippet from the content in the suggested ways, but the most successful is:

            [!reviews?&city=`[*cityTV*]`!]


            Using Susan's method in the PHP of the snippet:
            $city = isset($city) ? $city : '';

            When I call the snippet this way, it populates the heading in the plugin with the contents of the string. For instance, it says:
            Local Reviews for urlencode('Canton'), GA

            So I know that the TV definition is getting passed to the plugin from the TV through the snippet now, but it's sending it as a string rather than urlencoding the contents of the ('') and then passing that to the plugin.

            Feels like I'm standing in front of a tree seeing nothing but bark and groping for the leaves overhead.
              • 45946
              • 4 Posts
              I think I may have muddied the waters too much with that post. Here's what the current PHP in the reviews snippet says:
              <?php
              $agent = urlencode($_SERVER['HTTP_USER_AGENT']);
              $state = urlencode('GA');
              $city = isset($city) ? $city : '';  
              $radius = "5";
              $showMap = "yes";
              $showFavorites = "";
              $techEmail = "";
              $reviewStart = "1";
              $checkinStart = "1";
              $reviewCount = "25";
              $checkinCount = "15";
              $zoom = "11";
              $reviewCityUrl = "";
              $mapSize = "medium";
              $mapScrollWheel = "yes";
              $fbLike = "";
              $fbComment = "";
              $token = "clienttokennumber";
              $url = "http://api.site.com/plugin/vendorstring";
              $response = file_get_contents($url);
              return $response;
              ?>


              Successful setting of $city directly in the PHP snippet without use of TV was
              $city = urlencode('Atlanta');


              Here's how the TV-qualified snippet is called from the Resource content:
              [!reviews? &city=`[*cityTV*]`!]


              Current TV definition in the cityTV definition field on the Resource page is:
              urlencode('Atlanta')


              Return from plugin is the heading of:
              Local Reviews for urlencode('Atlanta'), GA
              ...without limiting the reviews to the Atlanta geo.

                • 45946
                • 4 Posts
                "I get by, with a little help from my friends!" GOT IT!! OK, here is how it works:

                Here's how the TV-qualified snippet is called from the Resource content:
                [!reviews? &city=`[*cityTV*]`!]


                TV definition in the cityTV definition field on the Resource page is:
                Atlanta


                Modified Susan's tip, so PHP line is as follows:
                $city = isset($city) ? $city : urlencode('');


                THANK YOU, breezer and sotwell!!
                  • 52128
                  • 29 Posts
                  Hi,

                  I am trying to replace kilometer to miles to just US, AU and UK. I have created a TV for Kilometers and add it to the template. When I add this the page is blank. Does anyone know what error I did in the code?

                  $tv = $modx->getObject('modTemplateVar'),'Kilometers');
                  
                  if(isset($_SESSION['country_code'])&&strtolower($_SESSION['country_code'])=="en"||strtolower($_SESSION['country_code'])=="gb"||strtolower($_SESSION['country_code'])=="au"||strtolower($_SESSION['country_code'])=="us"){
                  	$tvKilometers = ceil(intval($pTmp[0])/1.6093)." miles";
                  	
                  }else{
                  	$tvKilometers = $tv[0]." km";
                  }
                  
                  ?>
                  <li><strong>Distance:<span><?php echo $tvKilometers;?></span></strong></li>


                  Thank you in advance

                  Magz
                    • 3749
                    • 24,544 Posts
                    The modTemplateVar object doesn't hold any values other than the default.

                    I think you want the modTemplateVarResource object's 'value' field.

                    $tvId = 12; /* change to the ID of the TV */
                    $docId = $modx->resource->get('id');
                    
                    $tvr = $modx->getObject('modTemplateVarResource', array('tmplvarid' => $tvId, 'contentid' => $docId));
                    $value = $tvr->get('value');
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting