Email with predefined subject, from a Kirby Tag

I know it is possible to use “subject” in the email, when you use it as a helper.

But it is not possible, when used as a Kirby Tag;

(email: bastian@getkirby.com subject: My subject text: Send me an email)

This doesn’t work, only with this fork.

Is there any reason why it does not work in a tag (out of the box)?

The helper and the Kirbytag do completely different things. While the helper allows you to send an email from PHP, the tag embeds an HTML mailto: link on your page. It’s an apple to pear comparison. :smiley:

If you need this feature, why don’t you use the fork? You can put it in your site/tags directory and it will override the built-in tag.

Thanks, I know tags != helpers - but I thought their options were (about) the same.

The email-tag contains things like address, text, class, ref, etc… so I was wondering why it didn’t contain a subject option.

I solved it with the fork - but I prever to use as less additions as possible :smile:

It’s a bit like “why does the apple I bought not ship with OS X? It has the same name, doesn’t it?”. :smiley:

The tag could include subject, but currently it doesn’t. Maybe it will in the future. :smile:

Cool :smile:

I totally understand it - so it’s not quite a question, it’s more like a suggestion!

You could go ahead and create a pull request with this feature.

Nah… the fork works fine - Christian is getting crazy from all those requests - I’m afraid…


I forked the fork (yeah!) and added a title option to the tag;

(email:info@domain.com subject:my subject text:click on me title:click to mail me body:yes, i can click)

<?php
kirbytext::$tags['email'] = array(
  'attr' => array(
    'text',
    'subject',
    'title',
    'body'
  ),
  'html' => function($tag) {
    $email   = $tag->attr('email');
    $text    = $tag->attr('text', $email);
    $title   = $tag->attr('title', $email);
    $subject = rawurlencode($tag->attr('subject',null));
    $body = $tag->attr('body',null);
    $body = rawurlencode(str_replace('\n', "\n", $body));
    $query   = ($subject || $body) ? '?' : '';
    $query   .= ($subject) ? 'subject='.$subject : '';
    $query   .= ($subject && $body) ? '&' : '';
    $query   .= ($body) ? 'body='.$body : '';
    return '<a href="mailto:'.$email.$query.'" title="'.$title.'">'.$text.'</a>';
  }
);

UPDATE Of course the email is not encrypted in the source code, with this fork… and since the original already has the “title” attribute, it would come in handy when the subject attribute is added in a new version.

1 Like