Possible to prefill email body?

Hey KirbyFolks - I’m doing this within a page I created…Is it possible to prefill a couple of lines in the email body? Here is the code I’m working with:

(email: abcde@whatever.org subject: submission text: my great submission)

Not with the email Kirbytag. You can use a normal HTML link within Kirbytext however.

1 Like

I did not know that…giving a try now

That’ll work just fine, thx as usual

Coukld you describe this further? I don’t understand how this would solve the problem

Like this:

<a href="mailto:email@example.com?subject=subject&body=this%20is%0D%0Amy%20message">Contact us</a>
1 Like

Yes, this is exactly what I came up with, works nicely, and my user likes it. Easy peasy!

Okay got it thank you.

1 more question. I created my own tag for that purpose now. It looks like this:

(ticketmail: mail@example.com text: tickets kaufen body: Some E-Mail text subject: Some Subject)

with the following code:

  // ticketmail tag
  kirbytext::$tags['ticketmail'] = array(
    'attr' => array(
      'text',
      'body',
      'subject',
    ),
    'html' => function($tag) {

      $email = $tag->attr('ticketmail');
      $subject = '?subject=' . $tag->attr('subject');
      $body = '&body=' . $tag->attr('body');
      $link = 'mailto:' . $email . $subject . $body;

      return html::a($link, $tag->attr('text'), array(
        'class'  => 'button shopping-cart special',
        'title'  => $tag->attr('title'),
      ));
    }
  );

Is there a way to allow the “body: message” to use a new line character ( something like \n ) to have some very basic email formatting possibility. Somethink like this:

(ticketmail: mail@example.com text: tickets kaufen subject: Some Subject body: 
   Some E-Mail
   A second line text 
)

Is this possible or not?

if the body text is in html, you can use

%0A

to add a new line…

yes thank you that would be one way.

Maybe there is a more client friendly / “not so tech save person” solution?

if you need only to display this tag once, you could just define a field/structure where someone with panel access can just fill out subject, body to their hearts content which is basically much easier than trying to remember the (ticketmail: custom function)…

I agree with Carsten here, the tag is probably rather error prone.

^This
Kirby is supposed to be “easy” but almost every fix or solution I read has me creating or altering the php files. And then what, though!! How do my pages know to to pickup the new php coding? Do my mods to the page get run thru the php code at the time I hit save? I feel like the documentation is a little light when it comes to custom work

No tool is easy in the absolute; instead, they have features that may or may not be easy to use. And if you’re asking for things outside of that feature-set, things can get difficult, because the feature is not pre-built for you.

Additionally, with many publishing tools there are two main type of features:

  1. Core features that can be used without advanced technical knowledge, like the Kirby Panel.
  2. Advanced features that require more technical knowledge, like templating (easy enough), creating page blueprints (not too hard) or writing custom kirby tags (harder) or even custom PHP applications (quite harder).

That’s true of any publishing system. Take Tumblr for instance: writing or reblogging content is easy, picking a theme from the theme library is easy enough, but making changes to themes or writing your own is a daunting endeavor.

Some systems only offer the “easy” features, which means that they are very limited in what they can do (which can be a good thing). One example: Medium.

Other systems have a large ecosystem of plugins with administration panels for each plugin (for instance: WordPress, Drupal). This makes adding features “easy” (well, it kind of depends on how good the plugin is and how complex its feature set…), but can make the overall system maintenance harder.

What Carsten suggested was the creation of a custom Kirbytag. There is fairly complete documentation about that here:
Developer guide - How to create custom Kirbytags

The PHP code is not running continuously. Instead, when you load a page in the browser, the index.php at the root of your project will be run. This file will load many other files, and during that process your custom plugins and kirbytags definitions will be loaded too. Then it will load the controller for the requested page (if there is one), and then the template for that page.

When you make changes to the template or to another PHP file that impacts the current page (like a controller, or maybe a plugin), it will have no effect on a page already loaded in a browser tab, but it will have an effect when you reload that page.

2 Likes

I used %0D for a new line

Sometimes, there is more than one solution to a problem, from a rather easy one like just using html in your text files, to more complicated solutions like overwriting an existing tag or creating a new one, to completely different approaches like the one @carstengrimm suggested.

That does not mean that you have to keep changing your code all the time, if you are fine with a particular solution. Just pick the one that suits you or your client best. Kirby does give you this freedom.

If you have any suggestions how we can improve the docs, we’d love to hear you. Please post them either here or ideally as an issue in the getkirby.com repo on GitHub.