I have a cck text field field_review_comments which I want to automatically generate the title for the node. I am using the token [field_review_comments-raw] in order to generate the title, but Automatic Nodetitles module makes the whole content of the field as the title. I only want the first 30 characters from this field to be part of the title. Is there some way to trim it down to the first 30 characters?

Also what is the difference between raw and formatted? I am not sure which token to use, [field_review_comments-raw] or [field_review_comments-formatted]

CommentFileSizeAuthor
#6 668308-6.patch592 bytesmanish-31
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Zythyr’s picture

Help???

BassPlaya’s picture

Status: Active » Needs review
Issue tags: +Drupal 6, +replacement, +character, +truncate, +pattern

I have come up the exact same problem and after a three hours search and trial and error I found a solution.
I have to say that it works for me now on my local install of Drupal 6, so let's hope it's going to do the same thing on the server.
I'm also not really a coder so I'm not sure if I'm doing this correctly. If anyone knows how to do it better, please correct me.
Here's the code you'll have to use and it will do exactly what you want it to do: truncate characters of a replacement pattern for automatic node titles.

<?php 
$mystring = '[field_review_comments-raw]'; 
return drupal_substr($mystring,0,30)."..."; 
// the second number is the number of characters after which you want it to truncate
// and then it concatenates with an ellipsis
?>

The $mystring is something you can name whatever you want but make sure it doesn't conflict with any other string coz I might think that it could.

fago’s picture

Status: Needs review » Active

no patch.

mototribe’s picture

Status: Active » Closed (works as designed)

excellent, that worked for me too (Drupal 7).
Thank you!

giorgio79’s picture

Title: Trim the title to limited amount of characters » Trim the title to limited amount of characters and add ellipsis
Version: 6.x-1.2 » 7.x-1.x-dev
Component: Documentation » Code
Status: Closed (works as designed) » Active

Would be great to have this as a checkbox option next to the auto title field :)

Similar to #668308: Trim the title to limited amount of characters and add ellipsis

manish-31’s picture

Assigned: Unassigned » manish-31
Issue summary: View changes
Status: Active » Needs review
Issue tags: -Drupal 6, -replacement, -character, -truncate, -pattern
FileSize
592 bytes

With this patch I have restricted the maximum length of the generated title to be 70 characters, which was 255 characters earlier. Please review this patch.

gaurav.kapoor’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.