DaveP

TextFormatter Insert Dummy Content

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

Share this post


Link to post
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

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thanks for this module @DaveP 

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

  • Like 2

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
7 minutes ago, DaveP said:

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

it's just too easy to create them :D

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Lex Sanchez
      Video or Social Post Embed
      Based on the TextformatterVideoEmbed module developed by Ryan Cramer, we have added the possibility to embed publications of the main social networks Facebook, Twitter and Instagram.
      ProcessWire Textformatter module that enables translation of YouTube, Vimeo, Instagram, Facebook, Twitter or Issuu URLs to full embed codes, resulting in a viewable video or social post in textarea fields you apply it to.
      How to install
      Download or Clone from Github: https://github.com/lexsanchez/VideoOrSocialPostEmbed
      Copy the VideoOrSocialPostEmbed.module file to your /site/modules/ directory (or place it in /site/modules/VideoOrSocialPostEmbed/).
      Click check for new modules in ProcessWire Admin Modules screen. Click install for the module labeled: "Video or Social Post Embed".
      Now you will be on the module config screen. Please make note of the config options and set as you see fit.
      How to use
      Edit your body field in Setup > Fields (or whatever field(s) you will be placing videos in). On the details tab, find the Text Formatters field and select "Video or Social Post Embed". Save.
      Edit a page using the field you edited and paste in YouTube, Vimeo, Facebook, Twitter, Instagram and/or Issuu URLs each on their own paragraph.
      Example
      How it might look in your editor (like TinyMCE):
      How it works
      This module uses YouTube, Vimeo, Instagram, Facebook, Twitter and Issuu oEmbed services to generate the embed codes populated in your content. After these services are queried the first time, the embed code is cached so that it doesn't need to be pulled again.
      Configuration
      You may want to update the max width and max height settings on the module's configuration screen. You should make these consistent with what is supported by your site design.
      If you change these max width / max height settings you may also want to check the box to clear cache, so that YouTube/Vimeo/Facebook/Twitter/Instagram/Issuu oembed services will generate new embed codes for you.
      Using with Markdown, Textile or other LML
      This text formatter is looking for a YouTube, Vimeo, Instagram, Facebook, Twitter or Issuu video URL surrounded by paragraph tags. As a result, if you are using Markdown or Textile (or something else like it) you want that text formatter to run before this one. That ensures that the expected paragraph tags will be present when VideoOrSocialPostEmbed runs. You can control the order that text formatters are run in by drag/drop sorting in the field editor.
      Copyright 2018 by Ryan Cramer / Updated by Lex Sanchez
    • By kixe
      Email Verification
      This module provides functions to validate email adresses and hosts. The module generates a textfile for blacklisted mailhosts (trashmail), which will be always up to date.
      Download
      https://modules.processwire.com/modules/email-verification/
      API
      // get module $mailcheck = $modules->get('EmailVerification'); // return bool/ string - automatted update of blacklist file $mailcheck->blacklisted(email|domain) // return bool - validate a top level domain, checks against IANA list $mailcheck->validTLD(tld) // return array of punycoded TLDs - cyclic updated, data pulled from IANA $mailcheck->getTLDs(cycle=2592000) // return bool - checks syntax converts to punycode $mailcheck->validDomainName(domain); // return bool - checks punycode encoded syntax $mailcheck->validHostName(host); // return bool - checks syntax and accessibility $mailcheck->validHost(email|domain) // add a single value to blacklist $mailcheck->addToBlacklist(email|domain) USAGE
      $mailcheck = $modules->get('EmailCheck'); $email = 'susi@trashmail.com'; if($mailcheck->blacklisted($email)) echo 'Email Provider not allowed'; if(!$mailcheck->validHost($email)) echo 'Mailhost not available'; Example blacklist file:  blacklist.txt
       
    • By teppo
      Code Blocks Textformatter is a tiny Textformatter module I cooked up to add support for code blocks to text/textarea/RTE fields on some of the sites I work with. Unlike a full-blown Markdown Textformatter – which is something that we already have in the core – this module simply adds support for fenced and inline code blocks.
      The syntax is based on the GitHub code block documentation, so please refer to that for additional instructions. The README at GitHub also includes some basic examples. As with any Textformatter, in order to enable this one, install it and enable it via field settings. Note that there's no syntax highlighting built in (at least for the time being), so use a tool of your choice for that – personally I prefer Prism.js.
      Since this module doesn't use a Markdown tool behind the scenes, but rather some home baked regular expressions, there's always the possibility that I've missed something – but please let me know if you use this module and run into any issues. On the other hand this module should be relatively fast and unobtrusive, as there are no unnecessary bits of code to run 
      GitHub repository: https://github.com/teppokoivula/TextformatterCodeBlocks Modules directory: http://modules.processwire.com/modules/textformatter-code-blocks/