Sofia Violet Emilie Blackthorne (
sofiaviolet) wrote2009-05-07 06:43 pm
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Entry tags:
tutorial: random text in your layout
Notes: This will require creating/editing a layer (theme or layout). The directions below are intended for use on Dreamwidth, but this kind of thing does also work on LiveJournal, and possibly on clones.
To see random text in action, view my journal in my style. The text appears in the left sidebar, beneath the pink rose. Refresh the page a couple of times to see the text change. If you'd like to view the code for my layout, here's the raw code and with syntax highlighted.
I am willing to help people troubleshoot their implementations of this code, but my time is not infinite and my skills are limited. But feel free to ask, and I'll do what I can.
The concepts used for this code can also be used to randomize header graphics and background images.
To see random text in action, view my journal in my style. The text appears in the left sidebar, beneath the pink rose. Refresh the page a couple of times to see the text change. If you'd like to view the code for my layout, here's the raw code and with syntax highlighted.
I am willing to help people troubleshoot their implementations of this code, but my time is not infinite and my skills are limited. But feel free to ask, and I'll do what I can.
1. Get ready to edit a layer.
If you are already using a custom theme or layout layer, then click the Edit button.
If not, then create a layout-specific theme layer for your current layout.
2. Find the function calledPage::print()
.
If you don't have that function in the layer you're currently working on, get the code for it from the appropriate public layer and paste that into your layer.
3. You will be entering the first part of the code on a new line right afterfunction Page::print() {
.
var string[] freetext;
$freetext[0] = "f00";
$freetext[1] = "bar";
$freetext[2] = "baz";
$freetext[3] = "quux";
var int randomtext;
$randomtext = rand(0, ((size $freetext) - 1));
4. Replace the words inside the double quotes with whatever text you want (including HTML tags - just be sure to escape any internal double quotes, ie <img src=\"http://site.com/pic.jpg\">).
You can add more $freetext[n] items - just be sure to number them consecutively, put double quotes around each item, and end each line with a semicolon.
5. Within the Page::print() function, find the place where you want your text to appear and paste the following on a new line:println "$freetext[$randomtext]";
Make sure not to damage any of the surrounding code.
6. Hit the Save & Compile button. If it throws an error, then something is in the wrong place, or you've made a typo. Check the box with the error message for more details.
If it compiles properly, then open up your journal and make sure the text appears the way you want it to.
The concepts used for this code can also be used to randomize header graphics and background images.