3

I've a custom module I'm sending the content of node and views by email. The module first render the node/view and wrap the results around common template.

But when my views and node content are build, they contain links are relatives. I'm looking for a way to force these links to be absolute (ie. with domain and protocol).

The url() and l() functions can be used to output absolute links, but I don't see a way to force this behavior on all links. I'm planning to process the content as an HTML string to extract all links and complete the URL when required. But this doesn't seem very efficient.

Is there another way to ensure absolute URL ?

Here is the code used to render the content for nodes and views:

//For nodes
$node = node_build_content($node, FALSE, FALSE);
$node->body = drupal_render($node->content);
unset($node->teaser);
node_invoke_nodeapi($node, 'alter', FALSE, FALSE);
$content = $node->body;

//For views
$content = $view->preview($display_id, $arguments);
3

Have a look at this module: Pathologic

Pathologic is an input filter which can correct paths in links and images in your Drupal content in situations which would otherwise cause them to “break;” for example, if the URL of the site changes, or the content was moved to a different server. Pathologic can also solve the problem of missing images and broken links in your site’s RSS feeds. See more example use cases on the documentation page.

  • I've used pathological for the same thing - sending emails. – Greg Mar 14 '11 at 16:19
  • I ended up re-using the pathologic filter function on my mail body to ensure absolute link. – Pierre Buyle Mar 15 '11 at 11:01
0

How about adding the BASE tag to your page.tpl.php:

<base href="http://www.yourooturlhere.com/" />

See: http://www.w3schools.com/tags/tag_base.asp

  • I haven't tried this recently, but AFAIK, some (mainly web based) email clients do not support this, leaving you with broken links. – marcvangend Mar 14 '11 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.