Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-09-14 11:41:17

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,200
GitHub

Apostrophes/single quotes in article titles

Hi.
I’m using this in an article form to output some footer links in a ul:

<li><txp:permlink title='<txp:title /> was posted <txp:posted format="since" />'><txp:title /></txp:permlink></li>

…which outputs something like this on hover (article title in this case is I like hot toast):

I like hot toast was posted 4 hours ago

This is great, and exactly what I was expecting. However, if title contains an apostrophe, the hover now looks like this (article title in this case is I ate Stef's hot toast):

I ate Stef’s hot toast was posted 3 hours ago

Which is not so great. Is there a way to change the ' to an apostrophe? I was wondering if rah_replace would do it, but it seems a little overkill for the task.

Thank you in advance.

Last edited by gaekwad (2012-09-15 11:17:25)

Offline

#2 2012-09-14 13:31:50

etc
Developer
Registered: 2010-11-11
Posts: 5,123
Website GitHub

Re: Apostrophes/single quotes in article titles

If rah_replace is already installed on the site, it’s fine to use it here. Otherwise, I can not find anything better than title='<txp:php>echo str_replace("&#39 ;", "''", title(array()));</txp:php> was posted <txp:posted format="since" />'

Edit: delete the space between &#39 and ;, textile is stronger than me.

Last edited by etc (2012-09-14 13:36:08)

Offline

#3 2012-09-14 13:40:25

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,200
GitHub

Re: Apostrophes/single quotes in article titles

Thank you, Oleg — rah_replace is already installed, so I’ll go ahead and use that.

Offline

#4 2012-09-14 17:13:47

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 355
Website

Re: Apostrophes/single quotes in article titles

or use double quotes

<a href="<txp:permlink />" title="<txp:title />" ><txp:title /></a>

but then the title should be no double quotes.. :)

Last edited by makss (2012-09-14 17:14:28)


aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)

Offline

#5 2012-09-15 10:47:15

etc
Developer
Registered: 2010-11-11
Posts: 5,123
Website GitHub

Re: Apostrophes/single quotes in article titles

makss wrote:

or use double quotes

Amazing, nice one!

Offline

#6 2012-09-15 10:51:31

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,200
GitHub

Re: Apostrophes/single quotes in article titles

makss wrote:

or use double quotes

Hi makss.
Thank you for your reply. The problem I have with double quotes is parsing <txp:posted format="since" /> as it contains double quotes and is important to the output. I can’t test it right now, but would this work:

<li><txp:permlink title=”<txp:title /> was posted <txp:posted format=‘since’ />”><txp:title /></txp:permlink></li>

Last edited by gaekwad (2012-09-15 10:51:50)

Offline

#7 2012-09-15 11:12:37

etc
Developer
Registered: 2010-11-11
Posts: 5,123
Website GitHub

Re: Apostrophes/single quotes in article titles

gaekwad wrote:

I can’t test it right now, but would this work:

<li><txp:permlink title="<txp:title /> was posted <txp:posted format='since' />"><txp:title /></txp:permlink></li>

Yes, it works, and that’s amazing. Not this one, but

<a href="<txp:permlink />" title="<txp:title /> was posted <txp:posted format='since' />" ><txp:title /></a>

will.

Last edited by etc (2012-09-15 11:16:18)

Offline

#8 2012-09-15 11:13:58

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,200
GitHub

Re: Apostrophes/single quotes in article titles

etc wrote:

Yes, it works, and that’s amazing. Txp parser does marvels.

Thank you again, Oleg – I am very grateful for your assistance.

Offline

#9 2012-09-15 11:16:50

etc
Developer
Registered: 2010-11-11
Posts: 5,123
Website GitHub

Re: Apostrophes/single quotes in article titles

Sorry, I was too fast. Actually, this one works too:

<txp:permlink title="<txp:title /> was posted <txp:posted format='since' />"><txp:title /></txp:permlink>

Txp parser does marvels.

Last edited by etc (2012-09-15 11:43:38)

Offline

#10 2012-09-15 16:59:36

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Apostrophes/single quotes in article titles

<txp:permlink title="<txp:title /> was posted <txp:posted format='since' />"><txp:title /></txp:permlink>

That shouldn’t be working, AFAIK.
Parsing tags in tags require simple quotes (at least, for a one-level depth).
The above line should be:

<txp:permlink title='<txp:title /> was posted <txp:posted format="since" />'><txp:title /></txp:permlink>

La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#11 2012-09-15 17:09:59

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,200
GitHub

Re: Apostrophes/single quotes in article titles

maniqui wrote:

<txp:permlink title='<txp:title /> was posted <txp:posted format="since" />'><txp:title /></txp:permlink>

Thanks, Julián, that’s good to know — exactly what I was using in my opening post.

Offline

#12 2012-09-15 19:16:41

etc
Developer
Registered: 2010-11-11
Posts: 5,123
Website GitHub

Re: Apostrophes/single quotes in article titles

maniqui wrote:

<txp:permlink title="<txp:title /> was posted <txp:posted format='since' />"><txp:title /></txp:permlink>

That shouldn’t be working, AFAIK.

That’s what I thought too, but I’m testing and retesting – it works. Could somebody confirm?

Offline

Board footer

Powered by FluxBB