Hi all.

Basically, I've set up an action that emails a customer after a content type is submitted. The email is functioning fine, however I require the path of the node to be printed in the email. I'm using pathauto to create the url in a format similar to: videos/rte567890

I need the customer to receive that path and not just simply something like: node/23

I'm able to print node id's, and all other types of node information, but I just can't seem to print the path created by pathauto. I thought there might be one of those token patterns, such as [node:nid] for the path, but alas.

I've tried many different ways of printing it including this way:
$node = node_load(array("nid" => $node->nid)); echo $node->path

I did that because I got a node ID result for this:
$node = node_load(array("nid" => $node->nid)); echo $node->nid

I've got the latest snapshot of token. I'm fairly new at drupal, an am not strong with php, but can get around it ok.

I'm almost pulling my hair out, so any help would be greatly appreciated. GREAT module by the way. If I can get this to work, I'll love it even more.

Comments

fago’s picture

Why do you load the node again?

echo $node->path;

should do it, if a path is set.

fago’s picture

Status: Active » Fixed
Yzzi’s picture

Hi Fago.

Thanks for the suggestion :) I've tried a million different things, and that was one of the first. It didn't work for me though, it just appears blank in the email.

I'm going to try the suggestion at post #2, but incase that doesn't work, do you have any other suggestions?

Thanks again for your help!

Yzzi’s picture

Hello again. Just finished trying the second suggestion, and it prints the path, but not the pathauto one. ie. it outputs "node/96"

Thanks for your help so far. Is there anything else I can do?

Yzzi’s picture

Status: Fixed » Active
fago’s picture

so is there actually a path alias? I see no other cause why it shouldn't work.

tostinni’s picture

Hi,
I was also wondering why does emails actions in rules doesn't support tokens, so I think we should set this as a feature request ?

fago’s picture

They do. Install the latest snapshot of the token module.

fago’s picture

Status: Active » Closed (fixed)
sjf’s picture

Title: printing a pathauto url in email » Printing a pathauto url alias in email or CCK field
Version: 6.x-1.0-beta3 » 6.x-1.x-dev
Status: Closed (fixed) » Active

Sorry for dragging up an old thread, but it wasn't clear if this was actually solved and I have been having a similar problem. When a node is created, I'm trying to populate a field with the URL alias. I applied the patch #127613: Provide tokens for node url and path (i.e. absolute and relative alias respectively) to get url alias tokens. Here is what I'm doing:

Create a triggered rule:
Event - Content is going to be saved;
Condition - Node is of type story;
Action - Populate a field with the token [node:url] which I can now use thanks to the token patch.

Now I create a story node. The node has a URL alias but the field is populated with the original URL in the form of http://mysite.org/node/999. If I then edit and simply resave the node, the field is populated with the correct URL alias, so I know that the token patch and the rule is working.

So I think this is the same as comment #4. Is the problem that the URL alias is being created after the rule is executed? I've tried altering the weight of the rule to 10 and even altering the weight of the rules module to 200 so it occurs as late as possible in the process. I've also tried changing the event to "After saving new content" but the problem remains.

sjf’s picture

Category: support » bug

I also tried creating a rule to send an e-mail on node creation with the token [node:url]. I got an email with the http://mysite.org/node/999 URL instead of the URL alias. The URL alias is definitely being created and I can't figure out why this isn't working.

Switching to bug report (not sure if this is correct as it relies on an uncommitted patch to Token).

sjf’s picture

Assigned: » Unassigned

Above response is spam. Unassigning...

mrtoner’s picture

Category: bug » support

I'm pretty sure there's no bug, as the Token patch works for me and I'm able to use [node:node-url] (as greggles prefers) in a Rules-generated email message.

sjf’s picture

Okay, I'm still stumped!

1. I have a clean install of Drupal 6.16.

2. Only installed modules are Rules 6.x-1.2, Token 6.x-1.x-dev (with patch #19 in #127613: Provide tokens for node url and path (i.e. absolute and relative alias respectively)), and Pathauto 6.x-1.3. Clean URLs are turned on.

3. I create a single triggered Rule to generate an e-mail when content is created. The body of the email contains the new tokens provided by the Token patch:
[node:path] --- Relative path to the node
[node:url] --- Absolute URL to the node

4. I create the content called TESTITEM and the URL alias of the node, generated automatically by pathauto, is http://example.com/content/testitem

5. I receive the e-mail which appears as follows:
/node/105 --- Relative path to the node
http://example.com/node/105 --- Absolute URL to the node

I don't know how to make my setup any simpler than that. For those who have this working, what extra steps am I missing to get the URL alias http://example.com/content/testitem in the e-mail?

If the rule is set to run when updating an existing node, rather than creating a new one, I get http://example.com/content/testitem in the e-mail. This suggests a module weights issue to me, that the url alias is not available to Rules on node creation. But Rules weight is set to 20 so it is last to execute.

mrtoner’s picture

sjf, do the new tokens appear available in the Token replacement patterns?

sjf’s picture

Yes, and I can use them when updating a node so I know they are working. I think they are just not available to Rules on node creation. Is there a way to test this? mrtoner, what weights do you have your Rules, Pathauto and Token modules set to?

shambler’s picture

sjf did you ever get a solution to this? I have the same problem, and have tried all the suggested solutions.

mrtoner’s picture

@sjf: Sorry, I missed your last post. Token is 10, Pathauto is 1, Rules is 100. Rules I changed from the default because of an issue with Notifications.

sjf’s picture

@shambler: No, I never found a solution.
@mrtoner: Thanks, same order as me then....

YK85’s picture

subscribing

tangamampilia’s picture

Finally I managed to solve partially this issue.

This worked for me. You need to create 2 Rules with this actions:

  • Content is going to be saved:
  • After saving new content:
    • Action: Send a mail to an arbitrary mail address
    • Params: Message [node:node-url]

The main problems comes when you create 2 or more contents with exactly the same url alias path. When this happens the second alias give you something like: http://mysite.org/node/999

If you want to avoid this issue you need to create a unique alias... so, you can try in this way: http://mysite.org/[node:title]/[node:raw]

Also theres another issue. If your node title is: "Hi, I'm high" your alias will be: http://mysite.org/Hi-Im-high (with capital letters).

So, I hope this can help to someone. I think this is a Pathauto issue, not a Rules issue.

Kronix’s picture

I'd be interested in hearing a clean solution to this as well.

benone’s picture

subscribe

codekarate’s picture

I have a similar issue that I am running into trying to send out email messages using the "Messaging" module. I have one email that is sent out during a cron run and the node path token gives me the correct alias.

The problem lies in the other email I am trying to send. I am sending it out by using the hook_nodeapi "insert" operation. This should send out the email immediately after the content has been created. It works great but the path is coming across as "node/#" instead of the pathauto alias.

I can confirm that the pathauto alias has been set as I adjusted my modules weight to be after pathauto, however no matter what weight I set, I can't get the token to be available.

My guess is this is not really a Rules issue and is most likely a pathauto/token issue. Any ideas?

mitchell’s picture

Status: Active » Fixed

Closing old issues. Please try the latest versions and reopen if still applies.

Status: Fixed » Closed (fixed)

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

mitchell’s picture

Component: Miscellaneous » Rules Core

Updated component.