Page 1 of 1

[SOLVED!] Random blocks of text

Posted: Mon Jul 28, 2008 3:21 am
by Andrew Prior
I'm developing a site where it would be helpful to have some random blocks of text in a sidebar. I'm not talking about random quotes of a few words, but maybe 200 words. The idea is for some basic "refresher info" to show up along side certain topics. 
(Using different templates is not an option.)

The random quotes tag from CMS Made Simple, and others I have seen, all assume only a line of text.  Does anyone know of a method I could use? 

TIA Andrew Prior

Re: Random blocks of text

Posted: Mon Jul 28, 2008 6:43 am
by Andrew Prior
I guess a Global Content block would do the trick as a "container" for text, as it will take formatting. So if I could randomise the global content block which appeared... :-)

Re: Random blocks of text

Posted: Tue Jul 29, 2008 12:25 am
by Andrew Prior
I think I've fixed this issue for myself. I guess a programmer would do it in 2 minutes :), but I'm a writer, so it's a different story!
I've only tested in IE 7 at this stage, so I may have surprises.
I imagine that some kind if if else statement could make it a lot tidier, too.

Step one, take Calguy's capture randomiser for images and make it a global content statement as per below
{capture assign='num'}{1|rand:3}{/capture} {* generate a random number between 1 and 3, assign it to 'num *}
I've called this 'rand0ne'

Step Two: Make up your three global content blocks.  I've called them blob1 blob2 and blob3

Step Three: Then in the template where the random text is to appear use the following code:

Code: Select all

{global_content name='rand0ne'}
{$num} {* this is just showing me that the random capture is working while I'm testing. *}
{if  $num == 3 } 
	{global_content name = 'blob3'}
{/if}
{if  $num == 2 } 
	{global_content name = 'blob2'}
{/if}
{if  $num == 1 } 
	{global_content name = 'blob1'}
{/if}
Then I get the appropriate content showing up and matching the $num variable.

Why do this? Well, the random quote tag doesn't take formatting or line breaks.  So in my case it's not suitable.  In this case I get some "random" text blocks which I will essentially use like a magazine call out in the side bar of a page.  They can have formatting and links. So we will have ongoing discussions on a topic, and for newcomers there will be a random dispaly of some of the foundational articles and boundaries of the discussion in a condensed form. A person can follow the links to the full article.
Andrew

Re: [SOLVED!] Random blocks of text

Posted: Tue Jul 29, 2008 12:29 am
by calguy1000
{capture assign='num'}{1|rand:3}{/capture}
{capture assign='blobname'}blob{$num}{/capture}
{global_content name=$blobname}

Re: [SOLVED!] Random blocks of text

Posted: Tue Jul 29, 2008 12:32 am
by calguy1000
{capture assign='blobname'}blob{1|rand:3}{/capture}
{global_content name="$blobname"}

Re: [SOLVED!] Random blocks of text

Posted: Sat Aug 02, 2008 10:04 am
by Andrew Prior
Programmers!  :-)
Thanks calguy