I would like to use a "dynamic" variable (for lack of better words) in my plugin settings. I am sending whomever fills out my contact form a welcome email. I'd like to be able to include the persons name if I could.
Here is my settings file:
_settings.html
{{
forms.textareaField({
label: "Welcome email Message"|t,
id: 'welcomeEmailMessage',
name: 'welcomeEmailMessage',
instructions: "The email message that is sent to that the person who filled out the contact form."|t,
value: (settings.welcomeEmailMessage ? settings.welcomeEmailMessage : "Thank you {firstName} from {siteName}"|t({ siteName: craft.app.siteName })),
errors: settings.getErrors('welcomeEmailMessage')
})
}}
I know {siteName}
is a variable that's available everywhere. {firstName}
is the name of my form input that I'd like to somehow hook into.
I have all of the information I need to send the email to the user - just not sure how to connect the dots between the service that sends the email and the settings so I can use {firstName}
and it will get replaced with the value of the firstName
input field.
Here is my service if it helps to see what I'm trying to do...
MyService.php
...
$email->toEmail = $contact->email;
$email->subject = $settings->guestSubject;
$email->body = $settings->welcomeEmailMessage;
...
EDIT Sorry, this is kind of hard to describe. I'll keep going maybe that will help.
I have a contact form plugin, that has a setting of welcomeEmailMessage
. That setting allows the admin to set the text to the email that is sent to whomever filled out my form. Think of it like a confirmation email.
But, instead of just saying "Hi there..." I was trying to grab the value of the firstName
input and inject that into the email message that resides in the plugin settings.
The email could then read: "Hi there Bob..."
I have attached a screen shot of my settings page.
So you can see in the image I have {firstName}
in the textarea. I'm struggling on how to grab the value from the contact form - and inject it into that template variable.
It looks like it's very similar to the "Email Settings" area within the CP. Only instead of getting the dynamic parts from the install settings, I want to get the values from the form that was submitted.
Hope that helps?
EDIT
Reading though the comments, I'm struggling a little about how to implement them.
Here is my welcomeEmailMessage
. It's located in my plugin's directory/templates
html
<html>
<body>
<div>
Hello, {{ firstName }}
</div>
</body>
</html>
Then in my service I now have this:
php
$email = new EmailModel();
craft()->templates->renderString($settings->welcomeEmailMessage, ['firstName' => $contact->firstName]);
So now it seems like I need to tell my plugin how to get to that template?