CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • How to shorten/clip/truncate 'website' variable on search result display?
Pages: [1]

Author Topic: How to shorten/clip/truncate 'website' variable on search result display?  (Read 5641 times)

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
How to shorten/clip/truncate 'website' variable on search result display?
September 06, 2008, 10:14:39 am
Hi gang,

Some of our users have a long Website URL.  On the search result profile page it tends to STRRRRRRRETCH my template out past the desired borders.

I am looking for a way to truncate the Website URL for display purposes, or perhaps just replace it with a "Click here" or any solution to avoid the stretch!

http://soilscience.info/civicrm/profile?gid=1&search=1

See there, http://www.intermountainresources.com about 1/2 way down?

Sure would be nice if I could replace:

Code: [Select]
<a href="http://www.intermountainresources.com">http://www.intermountainresources.com</a>
with something more like...
Code: [Select]
<a href="http://www.intermountainresources.com">http://www.intermountain...</a>
or
Code: [Select]
<a href="http://www.intermountainresources.com">Click Here</a>
Ok so my first thought is "make a custom template", right?  Particularly this file: /CRM/Profile/Page/Listings.tpl   Ok, I searched the Forums here for all manner of things "custom template", "truncate variable", "substr" and found no solutions.  Next stop: the Smarty website.  I look at the documentation regarding variables, nothing.  I search their forums for some solution.  Nothing.  Been at an hour now, due diligence has been exhausted.  Help?

Here is the area of /CRM/Profile/Page/Listings.tpl that I need to change...but how?

Code: [Select]
{counter start=0 skip=1 print=false}
      {foreach from=$rows item=row }
      <tr id='rowid_{$row.contact_id}' class="{cycle values="odd-row,even-row"}">
      {foreach from=$row item=value name=directory}
        <td>{$value}</td>
      {/foreach}

In the meantime I have found a CSS based overflow: hidden solution ( more info: http://www.blakems.com/archives/000077.html ) but wondering if PHP and Smarty can accomplish the same thing more elegantly and with greater flexibility?  The CSS based solution is clunky and requires multiple custom templates depending on number of fields, without regard for varying widths, and ends up cutting off multiple fields' data, not just the Website URL.

Any help would be appreciated?
« Last Edit: September 06, 2008, 10:51:46 am by Stoob »
Try CiviTeacher: the online video tutorial CiviCRM learning library.

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: How to shorten/clip/truncate 'website' variable on search result display?
September 06, 2008, 11:40:42 am
I think using custom  templates is a right solution for your problem.
check http://wiki.civicrm.org/confluence/display/CRMDOC/Customize+Built-in+and+Profile+Screens

Once you setup custom template for eg: custom_templates/CRM/Profile/Page/Listings.tpl

Modify the the file to truncate website address using truncate function

http://www.smarty.net/manual/en/language.modifier.truncate.php

HTH

Kurund
Found this reply helpful? Support CiviCRM

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: How to shorten/clip/truncate 'website' variable on search result display?
September 06, 2008, 02:54:36 pm
Thanks for finding that Truncate function!

Slight problem, Truncate wants to cut the variable in the middle, and only allows for word breaks, not link breaks.

For instance:
Code: [Select]
{$value|truncate:30:"...":true}
Would take the value:
Code: [Select]
<a href="http://www.mywebsite.com">http://www.mywebsite.com</a>
And truncate it to:
Code: [Select]
<a href="http://www.mywebsite.
Which will obviously break the HTML of the page.  I see no way with Smarty Truncate to make a distinction between the text and the link code itself, it's just all one big string to Smarty.  I took a look at 'strip_tags' and 'replace' and 'regex_replace'functions, which with a lot of effort might render a usable result, but at this point that seems very bloated comparted to just adding a substr() somewhere in your CiviCRM code.

So now I must hack a function within CiviCRM, yes?   Is this possible?  If so what file do I hack?  Is there an alternative?

« Last Edit: September 06, 2008, 03:04:49 pm by Stoob »
Try CiviTeacher: the online video tutorial CiviCRM learning library.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: How to shorten/clip/truncate 'website' variable on search result display?
September 06, 2008, 08:15:36 pm
Quote from: Stoob on September 06, 2008, 02:54:36 pm
So now I must hack a function within CiviCRM, yes?   Is this possible?  If so what file do I hack?  Is there an alternative?

u can hack this file: CRM/Core/BAO/UFGroup.php

search for home_URL (line 762 or so)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • How to shorten/clip/truncate 'website' variable on search result display?

This forum was archived on 2017-11-26.