Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#31 2011-05-03 10:21:19

MyOtheHedgeFox
Member
From: Russia
Registered: 2010-11-06
Posts: 10
Website

Re: smd_random_text: Pull random items from the TXP environment

Thanks for the quick answer! =)
Could you also add a small example with this point to your plug-in description? IMO, I wouldn’t guess that I can use something like \n%\n as a regex’ed delimiter without caring much about the regular expressions syntax, without having an example in front of the eyes.

Last edited by MyOtheHedgeFox (2011-05-03 10:26:27)

Offline

#32 2011-05-03 11:16:24

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,476
Website GitHub

Re: smd_random_text: Pull random items from the TXP environment

MyOtheHedgeFox wrote:

Could you also add a small example with this point to your plug-in description?

Sure. I’ll make an example up and add it to the help at some point.


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#33 2011-05-03 15:12:28

MyOtheHedgeFox
Member
From: Russia
Registered: 2010-11-06
Posts: 10
Website

Re: smd_random_text: Pull random items from the TXP environment

Yay!

(a plenty of dancing happy kitties, holding geeky banners and screaming something like “STEF RULEZ LIKE OS/2!”)

Offline

#34 2011-05-03 15:15:35

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,476
Website GitHub

Re: smd_random_text: Pull random items from the TXP environment

MyOtheHedgeFox wrote:

STEF RULEZ LIKE OS/2!”

I’ll take that as a compliment :-)


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

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#35 2011-05-03 15:22:37

MyOtheHedgeFox
Member
From: Russia
Registered: 2010-11-06
Posts: 10
Website

Re: smd_random_text: Pull random items from the TXP environment

Well, that is. =) Some old Russian users still think that OS/2 was quite good. Those that met the Fidonet bloom, at least.

Er-r-r, I hope no punishment will follow this off-topic.

Last edited by MyOtheHedgeFox (2011-05-03 15:24:57)

Offline

#36 2012-05-19 05:05:05

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

Re: smd_random_text: Pull random items from the TXP environment

Hey Stef, love this plugin. I’m having some troubles getting a new random string on every page reload. Thought it might be asy_jpcache caching the site, but I disabled it and got the same result. I noticed that if I save the article with the tags in it again, I get a new result. Do you think it’s query caching? I emailed my host, waiting to see what they say.

Here’s the page: The 85 Dollar Computer Science Book Title Generator

Offline

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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,476
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.

Hire 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: 597
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,912
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,912
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,912
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: 9,388
Website GitHub Mastodon 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 | hblack.art | EMAP | A Sea change | Toolkit of Care
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: 12,476
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.

Hire 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,912
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,912
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

Board footer

Powered by FluxBB