Variables in Email link (Sugarcube)

Twine Version: 2.3.5 (Sugarcube)

So I’m trying to make a twine game where students will write text which then gets saved as a variable and can be emailed to their teacher easily.

I’ve found this html to open up and populate the OS’s default email, but I’m unable to get the story variables working within it:

<a href="mailto:$teacheremail?&subject=$studentwork&body=$work">Email your Teacher</a>

It should open up the default email (on OS that support it) and populate the email, subject and body automatically (the three variables have been set previously). Instead, it just treats the variables as strings.

I’m sure this can be fixed easily, but I’m not sure how. Thanks so much for your help!

I believe you have to put @ before href for the variables to be evaluated. Like this:

<a @href="mailto:$teacheremail?&subject=$studentwork&body=$work">Email your Teacher</a>

The reference is here under the “Attribute Directive” subsection.
https://www.motoslave.net/sugarcube/2/docs/#markup-html-attribute

1 Like

Hmm I tried that but it didn’t work :disappointed:

That’s close, but you need an attribute value which can be evaluated properly for the attribute directive to work. Something like this:

<a @href="'mailto:' + $teacheremail + '?&subject=' + $studentwork + '&body=' + $work">Email your Teacher</a>

That way it adds those strings and variables together into a single string.

Assuming that the variables are set properly, that should work.

Enjoy! :slight_smile:

2 Likes

Ah fantastic. This worked perfectly! I think I understand the theory now. Thankyou SO much! :slight_smile: