Skip to content

Instantly share code, notes, and snippets.

@AugustMiller
Created August 28, 2015 18:12
Show Gist options
  • Save AugustMiller/29fbdee374a0c56a765d to your computer and use it in GitHub Desktop.
Save AugustMiller/29fbdee374a0c56a765d to your computer and use it in GitHub Desktop.
Quickly transform a Kirby email field into a clickable email link
<?php field::$methods['asEmail'] = function($field) {
return html::a('mailto:' . $field->value, $field->value);
};
@AugustMiller
Copy link
Author

You can add this to site/plugins as field-as-email.php.

Then, call it like this:

echo $site->contact_email()->asEmail();

You'll get HTML that looks like this:

<a href="mailto:email@domain.com">email@domain.com</a>

@AugustMiller
Copy link
Author

Frankly, not sure if there is a convention for naming fields. Kirby core tends to use toThing()… But as seems more neutral to me??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment