Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Encoding/trimming output of <txp:site_url />
Hi.
A short question that hopefully someone can shed some light on. Is it possible to percent-encode the output of a tag (in this case site_url
)? If so, how might I achieve this?
In this instance, I’m using a template holding page with a hyperlink to another site. This hyperlink includes Google Analytics tags to determine the referrer. To avoid potential mishaps down the line, I want to avoid using clunky URLs like this:
http://example.com?utm_source=http://example.org&utm_medium=fruit&utm_campaign=banana
Instead, I’d like to either percent-encode the source URL…:
http://example.com?utm_source=http%3A%2F%2Fexample.org&utm_medium=fruit&utm_campaign=banana
…or, perhaps, strip the http://
from the referrer:
http://example.com?utm_source=example.org&utm_medium=fruit&utm_campaign=banana
I can use php
to chew the first part of the site_url
off, but as it’s technically deprecated I’d prefer a more reliable method for now and the future.
Thank you very much in advance for any suggestions, I’m grateful for your time, attention and expertise.
Offline
Re: Encoding/trimming output of <txp:site_url />
You could either use PHP, which is not ‘technically’ deprecated, or a plugin. For instance rah_function happily does encoding tasks:
<txp:rah_function call="urlencode" url='<txp:site_url />' />
Or you could use a PHP block:
<txp:php>
echo urlencode(parse('<txp:site_url />'));
</txp:php>
Offline
Re: Encoding/trimming output of <txp:site_url />
Thank you, Jukka – that’s perfect.
Offline