Making email address added as Short Description automatically mailto:

Permalink 1 user found helpful
I'm building a site for a solicitors practice and am using the thumbview template to display the profiles of all staff in a nice way on the top level Our People page (see attached).

The guys have come back and want all the email links to be clickable mailto: links. Is there any way I can make any text that is entered into the Short Description automatically link if it is a link? Is there an override or a little snippet someone could volunteer that would be great.

I can PM a link to the test site if anyone is interested.

Thanks,
Steve

1 Attachment

PassionForCreative
 
mesuva replied on at Permalink Reply
mesuva
After a quick google, I've found this regular expression:

echo preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $description);


So in your template, just put that in where you are outputting your description and change $description to the appropriate variable.

(I haven't tested the above, but it looks appropriate)
PassionForCreative replied on at Permalink Reply
PassionForCreative
Hi Mesuva, I've tried adding this in, inside the PHP tag that the description is mentioned in but I either get no effect or totally break the page. This is what I have at the minute:

<?php 
   defined('C5_EXECUTE') or die(_("Access Denied."));
   $textHelper = Loader::helper("text");
   $imgHelper = Loader::Helper('image');
   // now that we're in the specialized content file for this block type, 
   // we'll include this block type's class, and pass the block to it, and get
   // the content
   if (count($cArray) > 0) { ?>
                  <ul class="display">
   <?php 
   for ($i = 0; $i < count($cArray); $i++ ) {
      $cobj = $cArray[$i]; 
      $title = $cobj->getCollectionName();
      $link = $nh->getLinkToCollection($cobj); ?>   
                     <li>
PassionForCreative replied on at Permalink Reply
PassionForCreative
My colleague here had the idea to create a new page attribute called email and we used your code to parse it. This is what she came up with. Thanks for your help.

<?php 
   defined('C5_EXECUTE') or die(_("Access Denied."));
   $textHelper = Loader::helper("text");
   $imgHelper = Loader::Helper('image');
   // now that we're in the specialized content file for this block type, 
   // we'll include this block type's class, and pass the block to it, and get
   // the content
   if (count($cArray) > 0) { ?>
                  <ul class="display">
   <?php 
   for ($i = 0; $i < count($cArray); $i++ ) {
      $cobj = $cArray[$i]; 
      $title = $cobj->getCollectionName();
      $link = $nh->getLinkToCollection($cobj); ?>   
                     <li>