Jump to content

TextFormatter Insert Dummy Content


DaveP
 Share

Recommended Posts

I just made a textformatter module that allows you to insert dummy content (lorem ipsum style) in text fields via shortcodes.

Usage is simple - just type for example [dc3] into a textarea with this textformatter applied (plain textarea or CKEditor) and it will be replaced at runtime by 3 paragraphs of dummy content. It can also be used to populate text fields (for headings etc) using e.g. [dc4w]. This will produce 4 words (rather than paragraphs) at runtime.

The actual content comes from an included 'dummytext.txt' file containing 50 paragraphs of 'Lorem ipsum' from lipsum.com. The 50 paragraphs is arbitrary - it could be 10 or 100 or anything in between, and the contents of that file can be changed for your own filler text if you wish.

The slightly clever bit is that for any given page, the same content will be returned for the same tag, but the more paragraphs available in 'dummytext.txt', the less likely it is that two pages will get the same content (very roughly speaking - it's actually based on the page ID) so content selection is determinate rather than random, even though only the tags are saved to the db.

Update

Tags now work like this -

  • [dc3] - Show 3 paragraphs ([dc:3], [dc3p] & [dc:3p] all do the same).
  • [dc3-6] - Show 3 to 6 paragraphs randomly per page load ([dc:3-6], [dc3-6p] & [dc:3-6p] all do the same).
  • [dc3w] - Show 3 words ([dc:3w] does the same).
  • [dc3-6w] - Show 3 to 6 words randomly per page load ([dc:3-6w] does the same).

<End update on tags.>

If you think it might be useful, you can download it from GitHub and give it a try.

Edited by DaveP
Updated tags info.
  • Like 13
Link to comment
Share on other sites

Thanks for sharing it with us. I've been planning to do something like this but on the frontend.

I have but one request. Can you add a randomization logic?

[dc:3-6p] -> mt_rand(3, 6) // paragraphs
[dc:4-15w] -> mt_rand(4, 15) // words

 

Link to comment
Share on other sites

33 minutes ago, abdus said:

Can you add a randomization logic?

I think that can be done, although it's going to be stretching my limited regex skillz. :huh: Going to be some time next week at the earliest, though.

  • Like 1
Link to comment
Share on other sites

On 6.10.2017 at 4:47 PM, abdus said:

Thanks for sharing it with us. I've been planning to do something like this but on the frontend.

you know my dummy data module? 

showing (random) dummy data on the frontend would be as easy as that:

echo modules('RockDummyData')->getDummy()->loremipsum;

you would have to provide loremipsum text in the file loremipsum.txt in that case. and it does not support parameters like number of words or paragraphs but that could easily be added.

  • Like 1
Link to comment
Share on other sites

2 hours ago, bernhard said:

you know my dummy data module? 

It's hard to keep track of these great modules!

4 hours ago, psy said:

It's so easy to use and saved me heaps of time copy/pasting from lipsum.com

That's exactly why I made it. Thanks.

On 10/6/2017 at 3:47 PM, abdus said:

Can you add a randomization logic?

Just committed changes to enable pretty much exactly what you asked.

Tags now work like this -

  • [dc3] - Show 3 paragraphs ([dc:3], [dc3p] & [dc:3p] all do the same). (Same as original functionality.)
  • [dc3-6] - Show 3 to 6 paragraphs randomly per page load ([dc:3-6], [dc3-6p] & [dc:3-6p] all do the same). (New stuff.)
  • [dc3w] - Show 3 words ([dc:3w] does the same). (Same as original functionality.)
  • [dc3-6w] - Show 3 to 6 words randomly per page load ([dc:3-6w] does the same). (New stuff.)

(Anyone who has already downloaded and is happy has no need to update - the only changes are in response to @abdus's request above.)

  • Like 4
Link to comment
Share on other sites

@DaveP,

I've found this useful over the past week on a client project, so a big thank-you!

I think you should change the filename & classname of the module from "TextFormatterInsertDummyContent" to "TextformatterInsertDummyContent" though. At the moment, this module does not appear in the modules list grouped with all the other Textformatters but it is in its own, lonely, "Text" group. 

Unfortunately, this does require making a breaking change to the module, as the filename and class name (plus internal path names etc) all need to change.  The upshot of which is that the module can't be simply upgraded (at least, I think not.)

Anyway, I've forked your repo (here) and made some changes. I've also added code to randomise the output on each call. There is also a corporate branch that sources its 50 paragraphs from Corporate Ipsum.

  • Like 4
Link to comment
Share on other sites

This is odd - I thought I'd replied to this thread on Monday but there's no sign of that post. (Has there been a problem?)

Anyhow, I accepted & merged @netcarver's pull request, thanks for that.

And I think going forward that making the module configurable so that a selection of text files can be chosen from might add to its usefulness.

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...