We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 803
    • 6 Posts
    OK, my fist post, good to be here, thank you. I can’t find an answer I understand to my question elsewhere so here goes.
    I’m making a site where writers and editors will log in to the manager to create cafe reviews. As part of this they list the cafe contact details and open hours. As part of this, they list website and email addresses for the cafes. These need to be clickable to launch a new browser tab or email client message. I can make TVs as ’text’ type, no widgets, default values like <a href="http://www.mycafesite.com">www.mycafesite.com</a> and ask writers and editors to just replace "www.mycafesite.com", but this is not really neat to them. How can I set it up so that they just enter "www.mycafesite.com" or "[email protected]" and the back end takes care of the rest?
    Also, I know putting email addresses up may cause spam issues, so how do I make the site encrypt the entered emails?
    My background is as a graphic designer, recently learned to write HTML/CSS, no understanding of PHP (but can recognise it). After more than a year trying to push through with learning Drupal, I’ve only just started using Modx, and loving it! You’ve really got it right!
    So if any advice can be very step-by-step it will be much easier for me to understand.
      --
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      There are two or three plugins that "obfuscate" email addresses, I use ObfuscateEmail because it mixes methods in a random manner thus making it even harder for a script to be able to "scrape" email addresses from the page source.

      There is a TV widget (output formatter) for regular URLs, but not for email addresses. However, there is this Wiki page
      http://wiki.modxcms.com/index.php/Adding_TV_Widgets_without_hacking_the_core
        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
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Ok, I played around with that a bit and came up with this.
        Make your TV, type text, no output widget, no default content (unless you want a default email address if there isn’t one for the cafe, maybe to some general "info-@-somewhere" address).
        Make a snippet with this code:
        <?php
        $TVname = 'emailtv';
        if( $TVarray = $modx->getTemplateVarOutput(array($TVname)) ){
            	$tvOutput = $TVarray[$TVname];
        	if(empty($tvOutput)) return ''; //bail out if no value 
         	return '<a href="mailto:'.$tvOutput.'">'.$tvOutput.'</a>';
        }
        ?>

        Edit the $TVname value to whatever you named the TV.
        Put the snippet where you want the email address to be. It reads the TV and formats the email address, so all your document editor has to do is put the email address into the TV field.
          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
          • 803
          • 6 Posts
          First, thanks for your help. You’re a star!
          Unfortunately it’s not working for me just yet. So, here’s a run-down of what I did...

          To make clickable emails:
          -Made a TV called ’email’ type text, no widget, in a category called ’contact’, available to ’review’ template, saved
          -Made a snippet called ’emailclick’ in the ’contact’ category, and pasted in the code you supplied, but replaced your ’emailtv’ with my ’email’, saved, looks like this...

          <?php
          $TVname = ’email’;
          if( $TVarray = $modx->getTemplateVarOutput(array($TVname)) ){
          $tvOutput = $TVarray[$TVname];
          if(empty($tvOutput)) return ’’; //bail out if no value
          return ’<a href="mailto:’.$tvOutput.’">’.$tvOutput.’</a>’;
          }
          ?>

          -In the ’review’ template, I put [[emailclick]] where I want the email address to appear, looks like this...

          <td><p>[*address*],&nbsp;phone [*phone*]</p> <p>[[emailclick]]</p> <p>[*website*]</p></td>
          <<--! I know, I know, tables are no good! But this is actually tabular info, remainder of template uses divs !-->

          -The TV field appears in manager and I can put an address there, but no email address shows on preview.

          To make clickable URLs:
          -Made TV called ’website’, type URL, Hyeperlink widget, target blank, all other fields left with no value, saved
          -In the ’review’ template I put [*website*] where I want the URL to appear
          -Works fine in manager and preview page (yay!), BUT when I go to re-edit/re-save the document in manager and don’t change the website field, it changes http://www.mysite.com to $vwww.mysite.com on preview, and then also on re-re-edit in manager. Looks like some PHP thing going on here to me.

          Your thoughts and time here are very much appreciated. This is still 1000% easier for me than Drupal (no offence Drupalers, possibly my limitations more than yours!)

          Oh, by the way, ObfuscateEmail works a charm, thanks especially for that!
            --
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Ok, I did exactly what you did on my sottwell.com site, you can see the results in the right sidebar. I did do one other thing, though... I cleared my site cache. If you had put the tags in a document’s content, saving the document would have automatically cleared the cache (as long as that was set in the Configuration anyway, which it is by default on installation), but changing a template does not.

            I also made a quick URL/Hyperlink TV, you can see the result at the bottom of the sottwell.com homepage.
              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
              • 803
              • 6 Posts
              Sounds like a very simple question, but I don’t know the answer...
              How do you clear the site cache? Do you mean clear the cache in my browser, or is this different?


              <<edit
              A yes, I should read more before posting! All explained here...
              http://www.modxcms.com/document-caching.html
                --
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                No, in the Manager main menu, the Site tab, Clear Cache.
                  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