0

I'm using Kirby CMS and creating a little snippet which limits by posts by what number they are, and what date they are. A way to create a 'autopost' system basically.

$today = new DateTime("now"); //Declare today
$startdate = new DateTime("2013-09-12"); //Declare startdate
$interval = $startdate->diff($today); //Find the difference between startdate & today
$latest = $interval->format('%a'); //Declare $latest variable to be that interval, formatted as integer

So I have that little bit which creates my $latest variable which I can then use to control the posts that are displayed.

My problem is, I don't want to have to change my $startdate on every different kind of page template I have, so I want to make it site-wide somehow.

I tried putting it as a snippet with Kirby's snippet() function but that doesn't work. The snippets must be being brought into the page after the snippet has already been run I guess.

How can I make my snippet apply to my whole site?

suryanaga
  • 3,728
  • 11
  • 36
  • 47
  • You can try putting it in your file system. Write a code that writes startdate to a file and fetch it whenever you need from that file. ? – Shoogle Sep 27 '13 at 16:03

1 Answers1

1

PHP doesn't have site-wide variables. The best you can do is put the assignments in a script, e.g. site.php, and have all your pages begin with require 'site.php'; to initialize these variables.

Barmar
  • 741,623
  • 53
  • 500
  • 612