Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-03-17 18:04:58

tenthumbs
Member
Registered: 2004-11-22
Posts: 19

encode ampersands in custom fields

I’m using an external field to hold the url for external content in a linkblog kind of way, but the problem is that it won’t validate beacause for unencoded ampersands. So what i’m looking for is a way to encode the contents of that field.

There has been suggested an enchancement of the <txp:custom_field /> tag here , but I wondered if someone had any ideas on how to solve this in the current version of textpattern.

Offline

#2 2006-03-20 21:21:28

tenthumbs
Member
Registered: 2004-11-22
Posts: 19

Re: encode ampersands in custom fields

no one has run into the same problem?

Offline

#3 2006-03-20 21:28:15

placenamehere
Archived Plugin Author
Registered: 2004-11-21
Posts: 88
Website

Re: encode ampersands in custom fields

my initial thought would be to write a plugin that gets that filed for you and encodes it on the flyinstead of pulling it with txp:custom_field

but no, I haven’t hit this (since I haven’t used custom fields much) so I don’t have a solution already written and handy myself


Site: placenamehere.com
Microformat Plugin: pnh_mf

Offline

#4 2006-03-20 22:55:19

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: encode ampersands in custom fields

Or just makeup a simple htmlspecialchars plugin.

function ext_htmlspecialchars($atts, $thing = '')
{
    if ($thing)
    {
        return htmlspecialchars(parse($thing), ENT_QUOTES, 'UTF-8');
    }
}
<txp:ext_htmlspecialchars><txp:custom_field name="FieldName" /></txp:ext_htmlspecialchars>

Offline

#5 2006-03-20 23:22:21

tenthumbs
Member
Registered: 2004-11-22
Posts: 19

Re: encode ampersands in custom fields

Thank you so much, Mary!
That did the trick, and it also served as a good example on how to solve simple problems like this writing a plugin.

Offline

#6 2006-03-23 08:38:44

Jeff_K
Archived Plugin Author
From: Vancouver, British Columbia
Registered: 2005-08-19
Posts: 202
Website

Re: encode ampersands in custom fields

Mary! thats awesome. I have been thinking about tackling this for a while. Jeff.

Offline

Board footer

Powered by FluxBB