Access $site from with in kirbytext::$tags

As in the documentation described im able to use $tag->page to access page specific attributes but how do I access global site content?

What i try to do is to create a custom kirby tag which prints the global site email address.

kirbytext::$tags['siteEmail'] = array(
	'attr' => array(
		'text'
	),
	'html' => function ( $tag ) {
		$siteEmail = $site->companyEmail;
            return '<a href="mailto:' . $siteEmail . '">' . $siteEmail. '</a>';
	}
);
$siteEmail = kirby()->site()->companyEmail();

Don’t forget the parenthesis after companyEmail!

Note that it might be better to avoid the camelCase here, because otherwise the user will have to use it in their texts as well; maybe choose another name to prevent the double “ee” in the middle.

1 Like

That worked! Thank you. And you’re right, i’ll avoid camelCase here. Do you know why I have to add a colon and some text to get the email shown?

// works
(sitemail: lorem)

// does not work
(sitemail)

The colon is required to avoid that normal parentheses are converted to Kirbytags. You can however use this:

(sitemail:)
1 Like

Okay, didn’t know that. Thank you.