Charlesliam
Charlesliam

Reputation: 1313

How to set database value to CKEditor placeholder?

I'm using CKEditor 4 to replace the when creating an e-mail message. The message is mostly business letter template. I want to replace the some part such as in the letter template values from the database.

While searching CKEditor site, I found out this placeholder plugin. I know how to add the plugin to my CKEditor. BUt I wanna know how can I set this placeholder a value from my php variable. This variable holds database field column content for example $first_name.

I did search SO for any similar question but they usually skip the part I'm looking for.

Any suggestion is really appreciated

Thank you SO.

Upvotes: 3

Views: 1317

Answers (1)

sotoz
sotoz

Reputation: 3098

When you are using the CKEditor with the placeholder plugin you may have a text/html email template saved in your database with something like

Dear {f_name},
You owe us {money} Euros.

The tags {f_name} and {money} are examples and can be the placeholders you want. When you are populating the text for each email sent you can make a function like the following:

$email['body'] = $this->emails_model->fetch_your_email_body();
foreach ($users as $user){

    $email['body'] = str_replace('{f_name}', $user['first_name'], $email['body'] );
    $email['body'] = str_replace('{money}', $user['amount_to_pay'], $email['body']);

    $this->email->message($email['body']);
    $this->email->send()// send your email to each user (with or w/o the CI email class)
}

This will send a personalised email for every user you have in your $users array.

Upvotes: 3

Related Questions