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]

Comments

Help???

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.

Status:Needs review» Active

no patch.

Status:Active» Closed (works as designed)

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

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