Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#41 2014-07-31 10:33:31

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,464
Website

Re: smd_random_text: Pull random items from the TXP environment

Steph, or anyone…

I’m throwing out some random texts using the txp:variable method, with a pipe to separate them. It works. But I notice that if a given randon string has characters like ampersands or even a comma, those particular strings never get output. It’s like they get skipped.

I’ve tested this by removing various characters from strings that never show up, saving, and then cycling through again and the strings show up immediately. When adding the characters back, they disappear again.

The problem is that punctuation is kind of important for text strings if you don’t want to look like an illiterate dunce. How can I get things like commas (especially) and ampersands (less important) to show up?

Offline

#42 2014-07-31 11:54:34

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,270
Website

Re: smd_random_text: Pull random items from the TXP environment

Hi Destry, I by no means wish to undermine stef’s plugin but I thought that random texts could easilly be generated using native tags and the links tab. This method should be of help.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#43 2014-07-31 12:34:27

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,726
Website

Re: smd_random_text: Pull random items from the TXP environment

Destry wrote #282555:

How can I get things like commas (especially) and ampersands (less important) to show up?

Hmmm, it’s odd you’re having problems. Can you share your code so I might be able to figure it out? Are you using the plugin in an article or a Page/Form? If so, have you tried using notextile. or surrounding the tag with == marks to escape Textile?

Here’s my attempt that works fine:

<txp:variable name="writers"
     value="Huxley, Aldous | Shakespeare, William | Betjeman, John | O'Rourke, Sean | Penn & Teller" />

Herein lies a work by author: <txp:smd_random_text type="txpvar" source="writers" />

And, yep, the linklist method that Yiannis mentions works fine as an alternative, though it may be slower than the plugin because it a) involves the database, b) uses MySQL’s rand() function which is slower still, especially as the number of items increases.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#44 2014-07-31 17:10:46

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,464
Website

Re: smd_random_text: Pull random items from the TXP environment

Here’s the code…

<p id="tagline">
<txp:variable name="taglines" value="Content. Design. Experiences.|Doin' it to it.|A good thing goin' on.|Neptune's viceroy.|Asterisms and dogs' bollocks.|Put this in your pipe.|Writing plain and true.|Essays and assays, I say.|Parfaitement parfait." />
<txp:smd_random_text type="txpvar" source="taglines" />
</p>

That’s sitting inside a Txp form that outputs the heading at wion.com, in this case rotating the quirky taglines. I’m not escaping textile or anything. But I don’t have spaces around my pipes. Needed?

The problem child here is “Essays and assays, I say.” With the comma it doesn’t output. If I take the comma out, it does. Likewise if I use an ampersand in place of “and” (for shorter string lengths), that string won’t output either. I’m not doing that now, but I’ve tested it.

Offline

#45 2014-07-31 18:57:05

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,464
Website

Re: smd_random_text: Pull random items from the TXP environment

It seems my lack of spaces around the pipes were indeed the problem. I added the spaces and all the strings show up. Huh. It paid to ask. Thanks Stef.

Offline

#46 2014-07-31 20:16:06

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,726
Website

Re: smd_random_text: Pull random items from the TXP environment

Destry wrote #282569:

It seems my lack of spaces around the pipes were indeed the problem

Strange, it’s not supposed to make any difference! I just tried copying and pasting your example above into a test article on my server (without any textile escaping) and it worked fine, displaying punctuation and everything.

Are you using the latest v0.14 of the plugin? And if so, I wonder if there’s either a random PHP skwiffle or a MySQL collation issue at work. Since I’m doing everything in English here, maybe it’s just barfing on the way your DB tables are set up (uhhh, or summat like that). Very long shot, that one.

Flummoxed.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#47 2014-08-01 08:34:10

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,464
Website

Re: smd_random_text: Pull random items from the TXP environment

Yep, 0.14. I’m using MySQL in EN mode too (I’ve always assumed), but I do have the French language pack installed. I even cleared my cache back when making the tests, thinking maybe they were just stuck in place (as it were), but that didn’t make any difference either.

In any case, the spaces work and that’s good enough for me. Great plugin!

Offline

Board footer

Powered by FluxBB