I might be missing something simple but I am trying to keep a template file as content-free as possible, e.g. used as a layout only. The template has a few placeholders like {NAME}, {MESSAGE}, etc.
Two quick queries:
1- Why are the placeholders in the template not replaced with values?
2- $subject = "{NAME} - subject" with new Swift_Message($subject); does not work but $subject = " - subject" with new Swift_Message("{NAME}" . $subject); does.
Your template file ends with .php but any PHP in it will not be executed, just FYI.
The decorator plugin can only operate on strings currently, so your template (part) will not be replaced unless you use file_get_contents() instead.
As for the comment about the way you pass subject there must be something going wrong before it ever gets to Swift since that's just basic PHP string concatenation you're doing. Swift doesn't care *how* you pass $subject, it just sees whatever is stored in it
Chris, many thanks for your response! Also $subject issue is sorted, I had {NAME } (note the space!) - I knew there was something silly somewhere (due to lack of coffee perhaps?).
Btw, it was a habit to create new files with .PHP - there are no PHP scripts in it although I might just rename it to plain HTML....
The 2nd array item will replace the first array item. What's the best way to ensure that each array will ALWAYS be different even if the destinations are identical?
d11wtq wrote:I'm not sure why you would ever have two of the same address.
When you get all the addresses, try using array_unique() or something.
Sorry my previous query was not clear - I meant if you were filling in a contact form (for testing or demonstration for example) that sends to yourself. You would have expected two different email content.
Problem is that for replacements to work correctly you need unique keys so how do you pass these keys to swift (instead of using email address a key in the array for example)?
Ah, I see. That's not really possible with just the one message if you use the default Replacements class. You'd have to send the message twice explicitly. You could implement your own Replacements class but then you'd need to have some way of figuring out which template you want based purely on the address.
dillion wrote:Ah shame but like you said it is a bit pointless sending two emails to one person using Decorator.
Although if I find a way to extend your class or rather a trick, I will post it here if interested.
I could come up with ways to do it but they'd never appear in the actual release. For example, exteding the decorating you could keep track of how many times you been asked for replacements for an address and offer different replacements based on that number of times Hopefully you'll see a way around it anyway. Swift is really simply supposed to provide units of code you can use to make things simpler...