Is it possible to do maths within Kirby's Panel using markdown?

Hello,

I was wondering if it was possible to do maths from within Kirby’s panel using markdown?

For example on my home screen I’d like to say something along the lines of,

Hi I’m Fred a 21 year old lego enthusiast

or in the footer

making spelling mistakes for 21 years

And in order to not update this text every year, I was hoping to do something like
[current year]-[birth year] = X
I know you can call current year using (date: Year)m and obv in this example birth year is constant. But I don’t have any ideas about the maths part.

I’m hoping someone in the community has a solution :slight_smile:
Grateful of any suggestions, Rob

You can create your own Kirbytag for this. Inside that Kirbytag, there can be arbitrary PHP logic. :slight_smile:

1 Like

Thanks Lukas, this worked like a dream!

<?php

kirbytext::$tags['datecalculator'] = array(
  'html' => function($tag) {
	  
	  $birthdate = new DateTime("2010-07-01");
		$today     = new DateTime();
		$interval  = $today->diff($birthdate);
	  
    return $interval->format('%y years');
  }
);

This is what I used if anyone is interested with the markdown simply (datecalculator: somevalue)

2 Likes