1

I am managing careers on a client's website, and am trying to properly add a mailto link below each career description with an email address from one of the publish fields, as well as adding the subject to be the entry title of the career. I can't figure out how to properly format the entry title with %20 instead of a space. How can I do this? Here is my current code:

<p><em>Applicants should email resumés to <a href="{mailto_email}" target="blank">{mailto_email}</a>.</em></p>

The client wants the email address to be displayed (not encoded), so I am just displaying everything as default. I'm assuming my code will look something like the following, but with the entry title formatted somehow:

<p><em>Applicants should email resumés to <a href="{mailto_email}?subject={title}" target="blank">{mailto_email}</a>.</em></p>
5

You should be able to use an available plugin to encode things for URLs. I haven't tried or used this plugin, but I think the syntax would be something like this:

<a href="{mailto_email}?subject={exp:url_encoder method='rawurlencode'}{title}{/exp:url_encoder}" target="blank">

As a last resort, you could also use PHP and run rawurlencode() on it, like so:

<a href="{mailto_email}?subject=<?=rawurlencode("{title}")?>" target="blank">

Remember PHP should be set to parse on the output stage.

2
  • The plugin encodes the title with "+" instead of "%20" (which is supposed to be safer then "+") but this will work. Thank you! I used the 'urlencode' method instead of 'rawurlencode' for the plugin, in case you decide to try it out yourself sometime. May 6 '14 at 19:01
  • 1
    Since in this case it's part of the query string (part of the URI after the ?), + is both safe and correct. (See "Query Strings" in the W3 URI specification. May 6 '14 at 21:29

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.