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.
php variable with site wide scope
-
29-06-2022 - |
Domanda
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?
Soluzione
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow