Skip to content

Instantly share code, notes, and snippets.

@dleatherman
Forked from bastianallgeier/home.php
Created June 1, 2012 16:03
Show Gist options
  • Save dleatherman/2853199 to your computer and use it in GitHub Desktop.
Save dleatherman/2853199 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
----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment