I am generating a title for a cck node type with the rules module. This title includes a taxonomy term, a cck date, and an "additional text" field that is optional. I would like this optional additional text, when entered and submitted, to display in the title with parenthesis around the field's content. When the field is left blank, I don't want the parenthesis. So I've tried writing some custom PHP rule that would create a new variable that is available to my "set node title" rule. Any suggestions how I can use PHP to concatenate the "Additional Text Field" with a set of parenthesis before passing the string to the "set title" action? Any help would be appreciated. Thank you!

Comments

itangalo’s picture

Assigned: Unassigned » itangalo
Status: Active » Closed (fixed)

I would suggest the following:

1. Activate PHP filter (which you probably already have done)
2. Add the action for modifying the node title (which you, again, probably already have done)
3. Enter a title similar to this: [taxonomy:term] [node:date] <?php if !is_null($node->additional_term[0]['value']) { echo '(' . $node->additional_term[0]['value'] . ')'; } ?>

Before implementing this, please note that I'm not a coder. There might be some mistakes in the code above. (And there are neater ways of writing the IF statement, using colons and stuff.)

Another way of doing this is to add two different rules for setting the title of a node -- one executed when the CCK field is empty, one when the CCK field has a value. Then you could use tokens only to set the title.
This solution would mean that two rules are evaluated each time a node is saved, instead of one. But if you're users aren't spamming the site with hundereds of nodes per minute that probably won't be a problem.

Good luck!
//Johan Falk, NodeOne, Sweden
PS: I'm not maintaining the Rules module, just helping with support questions. You are welcome to ask more questions at http://groups.drupal.org/rules

mitchell’s picture

Component: Miscellaneous » Rules Core

Updated component.