Skip to content

Instantly share code, notes, and snippets.

@bastianallgeier
Created February 6, 2012 07:57
Show Gist options
  • Save bastianallgeier/1750612 to your computer and use it in GitHub Desktop.
Save bastianallgeier/1750612 to your computer and use it in GitHub Desktop.

Flickr-style random greeting

To add a random greeting to your homepage for example, add a comma-separated field with greetings to content/home/home.txt. You also need to create a specific template for the homepage by adding site/templates/home.php. Use the code from home.php as a starting point for your homepage template.

<?php snippet('header') ?>
<?php snippet('menu') ?>
<?php snippet('submenu') ?>
<?php
// get the entire string and
// split it into an array by comma
$tokens = str::split($page->greeting());
// shuffle all tokens
shuffle($tokens);
// get the first one
$greeting = $tokens[0];
?>
<h1><?php echo $greeting ?></h1>
<h2><?php echo $page->title() ?></h2>
<?php echo kirbytext($page->text()) ?>
<?php snippet('footer') ?>
Title: Welcome to this nice website
----
Text: Some Text
----
Greeting: Hello, Hi, Hey, Howdy, Aloha
----
@CheDESIGNER
Copy link

Hi,

The texts in "Greeting:" are not Markdown ready, how do I edit greetings using Markdown syntax?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment