Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#37 2012-05-23 23:39:16

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,568
Website GitHub

Re: smd_random_text: Pull random items from the TXP environment

maruchan wrote:

Do you think it’s query caching?

Probably. I had to turn off Send last modified header on Advanced Prefs to get a random quote on each page refresh, though that does increase bytes served per page so you need to be frugal elsewhere if you want to keep the speed up.

If it’s not that then I don’t know what else it might be, sorry.


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

#38 2012-05-24 02:56:32

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 585
Website

Re: smd_random_text: Pull random items from the TXP environment

Thanks, Stef. I didn’t get anything from changing the header setting, and my host verified that query caching was enabled. I ended up rewriting it as a PHP script (the randomizer) and now I use smd_xml to pull in the script output. :-) I still had to disable asy_jpcache site-wide, but at least the titles aren’t cached any longer. Made me wonder if I could disable asy_jpcache per-article somehow; maybe I’ll look into it.

Last edited by maruchan (2012-05-24 02:57:45)

Offline

#39 2012-12-03 11:48:46

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

Re: smd_random_text: Pull random items from the TXP environment

Not surprising that I find a smd_ plugin available for something I need to try. ;)

I’m trying this… It starts out pretty standard procedure; a person clicks a category from a category list, they’re taking to a list of articles for that category. But then, above the resulting list of article titles, I have a short acknowledgement, like this:

“Oh, <txp:category>, eh? You {random string}! Here’s what I have for you…”

The {random string} might pluck things like: “sly dog”, “funky monkey”, “nasty thang”, etc.

Looking back over the thread, it looks like this might be a good way to approach it, as it keeps the various random strings out of the admin-side UI, as a form, article, or whatever.

Does that make sense to try? Something simpler?

Also, I guess you could have two random strings on the same page with each pulling from a different .txt file?

Ed.: Actaully, looking at the docs, it seems a simple string right in the tag might be perfect. I’ll try that and see what shakes.

Ed. 2 Well, that was too easy. ;) Excellent plugin!

Last edited by Destry (2012-12-03 12:36:19)

Offline

#40 2013-09-21 16:50:01

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

Re: smd_random_text: Pull random items from the TXP environment

This time I have a real question, as opposed to a false one. I basically want to do something like this with a sentence…

{Random string starter} constant part {random string ender}.

So that each randomization process throws the matching starter and ender strings.

I was thinking maybe the “sync” example in the Help was relevant, and I tried this for variables…

<txp:variable name="starter">Starter 1 | Starter 2 | Starter 3</txp:variable>
<txp:variable name="ender">Ender 1 | Ender 2 | Ender 3</txp:variable>

and then tag setup like…

<txp:smd_random_text type="txpvar" source="starter" limit="1" wraptag="p">
{smd_rnd_txt} constant part <txp:smd_random_text type="txpvar" source="ender" item_num="{smd_rnd_txt_chosen_item}" />.
</txp:smd_random_text>

But that doesn’t seem to work. Nothing outputs.

Not possible?

Offline

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

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,753
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,777
Website GitHub Twitter

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 | State Machines | NeMe @ github
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: 10,568
Website GitHub

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,753
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,753
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: 10,568
Website GitHub

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,753
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