0

I've got a function that should generate a link as such <a href="http://linklocation">Set Password</a>, which does happen, but it is generating as plain text.

My guess is that this is due to my use of the t() and l() functions in the manner I'm using them.

Here's my code:

  global $user;
  $account = new stdClass();
  $account->uid = $user->uid;
  $account->login = $user->login;
  $account->pass = $user->pass;
  $link = l('Set Password', user_pass_reset_url($account));
  $token = t(token_replace(variable_get('listing_edit_free_activated_page', 'Your free content has been activated. Thanks! @link')), array('@link' => $link));

As you can tell, I'm attempting to generate a one-time user login link with the text, "Set Password". The token_replace() isn't really relevant to this problem.

Am I completely without options here? I want to use both t() and l() here - there's not really an easy way to not use both that I can see.

How do I use both while still maintaining the structure of $link as a link?

2
  • what are you trying to translate? Set Password or Your free content has been activated. Thanks! i dont get it Mar 27 '14 at 16:07
  • Your free content and set password should both be translatable. But the former, not the latter specifically.
    – Jack Ryan
    Mar 27 '14 at 17:53
1

The t function's first argument is a string, and the second is a keyed array of arguments (search => replace).

The string your passing in is:

token_replace(variable_get('listing_edit_free_activated_page', 'Your free content has been activated. Thanks!'))

And the replacement your searching for it @link.

As the string @link does not appear in the string your passing in no replacements are made.

Here is an example where a replacement will be made:

$text = t("@name's blog", array('@name' => format_username($account)));
2
  • The variable_get is delivering a @link in this case, my apologies for not clarifying that. You can just as well imagine the default string containing it.
    – Jack Ryan
    Mar 27 '14 at 17:52
  • I fixed the example to be clearer.
    – Jack Ryan
    Mar 27 '14 at 17:59
1

The answer I was looking for was to change the placeholder to !link.

@link gives only the plain text

!link gives the raw information

%link HTML escapes and highlights

This example page is for Drupal 6, but has more information on the placeholders:

https://api.drupal.org/api/drupal/includes%21common.inc/function/t/6

0

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.