Page modified tag

Hello,

I would like to create a custom kirby-tag to output when the page was changed.
I tried this:

(page: modified)

<?php

kirbytext::$tags['page'] = array(
  'html' => function($tag) {
  	//tag attributs
	$modified = $tag->attr('modified');

    return $page->modified('d/m/Y H:i');

  }
);
?>

but do not work, what I do wrong ?

Hey @Perry,

several issues here:

  • your callable has to return (block type) HTML

  • you define a variable $modifiedthat you do not use

  • ($tag->attr('modified'): this attribute is not defined; to get the “modified” value, use $tag->attr('page')

  • $page is not defined

  • what is the purpose of the modified value in (page: modified)?

  • (on a side note) do not use a closing tag in PHP-only files

Possible solution:

<?php

kirbytext::$tags['page'] = [

  'html' => function($tag) {
    $options = []; // options array, e.g. class name
    $html = new Brick('p',  $tag->page()->modified('d/m/Y H:i'), $options);

    return $html;

  }
];

Thank you @texnixe for your help.

This is my tag, is that right?

<?php

kirbytext::$tags['page'] = [

  'html' => function($tag) {

  	$modified_attr = $tag->attr('page'); 
  	$html ="";
  	if($modified_attr == "modified") 
  	{	
    	$html = "Stand: ".$tag->page()->modified('d.m.Y H:i');
	}

	if($modified_attr == "created") 
  	{	
    	$html = "Erstellt: ".$tag->page()->created('d.m.Y H:i');
	}

    return $html;

  }
];

Almost. As I wrote above, you have to wrap that stuff into an HTML block type element, a div, p etc.