2

EE Version. 2.7.3

I am running rawurlencode on a field in a channel called description to encode it to pass on correctly to twitters sharing url string inside my template.

Example input: Check Out Company Names Latest Post!

so the result should be

 Check%20Out%20Company%20Names%20Latest%20Post!

When I echo it outside of the anchor tag it renders correctly with the proper encoding, but as soon as I echo out the variable inside the anchor tag, the %20 encoding is not rendered and regular spaces are in the URL again.

PHP

<?php   
    $description =  rawurlencode('{description}');
?>

Output:

 <a href="http://twitter.com/home?status=<?php echo $description; ?> {site_url}" class="popup">

Any ideas what's wrong?

1 Answer 1

2

It looks like you need to enable PHP in your template.

Alternatively, you could use a plugin for the URL encoding. For example URL Encode or CE String.

It's generally considered not the best practice to enable PHP in templates when an existing plugin or a custom-built plugin allows you to avoid it. Some rationale for that is in this Stack Overflow post, Is there ever a good reason to use PHP inside ExpressionEngine templates?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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