We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33657
    • 128 Posts
    I am trying to do a image variable. I want the output to force the URL to absolute, only if you are picking an item in the manager. but you also have the ability to obviously type in your own path.. like http://placeholder.it/700x300 for example.

    if i do something like [[+site_url]] or one of the default variables for the path I get unexpected results when using my own absolute URLS. ie "http://mywebiste.com/http://placeholder.it/700x300

    so my question is.

    what is the best way to accept any path i want, like a absolute URL path, and also accept file manager input and render it to absolute URL.

    relative urls won't work in my site scenario so it all must be absolute.

    thanks!
      • 4172
      • 5,888 Posts
      you can try to use an output - filter - snippet:

      <?php
      
      //[[+image:addSiteUrl]]
      
      if (strstr($input,'http://')) {
          $output = $input;
      }else{
          $output = $modx->getOption('site_url') . $input;
      }
      
      return $output;
      
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 33657
        • 128 Posts
        Boom! works great, thanks!
          • 33657
          • 128 Posts
          what about this:

          "image": "http://mywebsite.com/cms//cms/assets/components/phpthumbof/cache/70.7b4f07a987c16cf0df91c4319bd1f04951.jpeg",


          when I use the default phpthumbof properties and the snippet I am getting double folder's for the CMS folder.

          I am trying to find where that path is created for phpthumb but if anyone knows a quick answer that would be helpful!

          thanks. i don't really want to remove the CMS from the snippet do i, because it sounds like i'd be making a rule to fix a bug that is probably nested away somewhere in the settings.


          <?php
          //[[+image:addSiteUrl]]
          
          if (strstr($input,'http://')) {
              $output = $input;
          }else if (strstr($input, 'cms')) {
          	$input = str_replace('/cms/', '', $input);
              $output = $modx->getOption('site_url') . $input;
          
          }else{
              $output = $modx->getOption('site_url') . $input;
          }
          
          return $output;



          is there a way to remove CMS from the path in the options of PHPthumbof?? or do i really need to string replace it?

          [ed. note: zurie last edited this post 12 years, 7 months ago.]
            • 4172
            • 5,888 Posts
            what is your site_url
            what are your mediasource path and url - settings?

            how (with which file-path) are the image-urls stored in the db?
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 33657
              • 128 Posts
              well I got it working by just string replacing the CMS portion... but the root of modx is

              siteurl.com/cms/index.php

              never touched the mediasources path and url settings.. i keep hearing about them and I am sure that it would probably be something that would help. but I haven't uesd modx since 2.0ish.. so last time I used it we use to just do [[~[*id]]] and [[+site_url]] and all that jazz.. and i had a hard time finding where to set that up so i just have "web" as my media sources.