Page 1 of 1

[mod] multiple content placeholder for message templates

PostPosted: 6:47am, Tue 16 Jan, 2007
by danatang
Many of my administrators request multiple contents in template, so I made my solution as below:

in sendemaillib.php line:192 (original code)
///////////////////////////////////////////
if ($cached[$messageid]["template"])
# template used
$htmlmessage = eregi_replace("\[CONTENT\]",$htmlcontent,$cached[$messageid]["template"]);
else {
# no template used
///////////////////////////////////////////

And my solution is:
///////////////////////////////////////////
if ($cached[$messageid]["template"]){
# template used
$arr_content = preg_split('#\[CONTENT\]#', $htmlcontent, -1, PREG_SPLIT_NO_EMPTY);
$len = count($arr_content);
$i=0;
while($i < $len)
{
if($i == 0)
$pattern = "#\[CONTENT\]#";
else
$pattern = "#\[CONTENT".$i."\]#";
$cached[$messageid]["template"] = preg_replace($pattern,$arr_content[$i],$cached[$messageid]["template"]);
$i++;
}

$htmlmessage = $html_link.$cached[$messageid]["template"];
}else {
# no template used
///////////////////////////////////////////

The usage of multiple contents template is attached.

Besides, you can add any more contents as you need, just follow the usage.

My administrators are using the new feature very well, I do hope the improvement is helpful for all of you. If possible, the enhancement can be added to the next version of phplist.

EDIT: See also http://mantis.phplist.com/view.php?id=8970

How can i upload my usage file (template.rar)

PostPosted: 7:26am, Tue 16 Jan, 2007
by danatang
Sorry, I cannot upload my usage file (template.rar just 68 KB). Any help?

EDIT: See http://mantis.phplist.com/view.php?id=8970

PostPosted: 2:28pm, Tue 16 Jan, 2007
by Hernol
Great, can you add an issue here http://mantis.phplist.com/ and upload the files?

Second place holder doesn't work.

PostPosted: 11:20pm, Tue 23 Jan, 2007
by mscruse
Hello

This is a great solution and exactly what I need. I have made the modifications to the sendemaillib.php and created my template with two content place holders:

[CONTENT]

and

[CONTENT1]

When I send a message all my content appears in the first [CONTENT] place holder.

I created my content like this example:


Test test test 1 2 3

Blah blah blah

Testing 1 2 3

[CONTENT]
More content

This is the second place holder


This is what you had in your example word document.

Is there something that I am doing wrong?

I have attached my template file for you to look at.

Many thanks
Michael.

PostPosted: 1:01am, Wed 24 Jan, 2007
by danatang
Hi,
Did you mark this line in sendemaillib.php as below?

//$htmlmessage = $html_link.eregi_replace("\[CONTENT\]",$htmlcontent,$cached[$messageid]["template"]);

THANK YOU

PostPosted: 1:23am, Wed 24 Jan, 2007
by mscruse
Hello

Thank you for the resolution. I had just commented it out with # but as soon as I changed it to // it worked perfectly.

Many thanks
Michael.

PostPosted: 11:56am, Sat 05 May, 2007
by kurieuo
I have not tested this solution, but I agree this feature is a must. And with code already existing, would I'd think make it much easier to implement. :)

This causes a bug

PostPosted: 2:32pm, Fri 08 Aug, 2008
by bizzynate
I have discovered that your hack causes a very serious bug with respect to currency values in the message body. For example:

"It costs $35 to go..."

becomes

"It costs to go..."

It appears that somehow your hack is preventing the use of something that resembles a PHP variable. You might wish to rethink this a little. Also, please do us all a favor and make a note of your findings in Mantis, so this bug doesn't get released.

PostPosted: 4:42am, Fri 14 Nov, 2008
by Guest
This was working fine in our previous version of phplist but now I cannot get it to work. Our current version is 2.10.5. Any ideas?

PostPosted: 7:32pm, Sat 15 Nov, 2008
by bizzynate
Kate, did you reapply the hack after upgrading? The upgrade would have replaced the files that you had previously hacked...

PostPosted: 3:46am, Thu 27 Nov, 2008
by Guest
I'm a little confused by this. In the message, does the [CONTENT] placeholder go before or after the content it refers to?

Is it:

this is text of first content
[CONTENT]
This is text of the sceond content
[CONTENT]

OR

[CONTENT]
This is the text of the first content
[CONTENT]
This is the text of the second content

One other question. If I define 3 Contents in the templlate and only define 2 in the message, what happens?

Thanks,
Pete

PostPosted: 5:15am, Thu 27 Nov, 2008
by Guest
I figured out the answer to the previous reply I posted.

Everything seems to be working fine but I'm getting the problem with dollar amounts disappearing. Has anyone figured out how to fix this? I probably can't use this mod unless that's fixed since most of my messages have a $ amount somewhere in them.

Thanks,
Pete

PostPosted: 9:03pm, Sun 28 Dec, 2008
by rjc
Copy Pasted from the Mantis link for those who didn't look there, a fix for the $ bug; haven't tried it yet to know if it works, assume it does:


Danatang wrote on 11/08/08:

Thanks bizzynate!

I made fix as below:
//////////////////////////////////////////////////////////////////////
if ($cached[$messageid]["template"]){
# template used
$arr_content = spliti('\[CONTENT\]', $htmlcontent);
$len = count($arr_content);
$i=0;
while($i < $len)
{
if($i == 0)
$pattern = "\[CONTENT\]";
else
$pattern = "\[CONTENT".$i."\]";
$cached[$messageid]["template"] = eregi_replace($pattern,$arr_content[$i],$cached[$messageid]["template"]);
$i++;
}
$htmlmessage = $html_link.$cached[$messageid]["template"];
}else {

..............


Just please don't use it to send out messages such as "Office 2007 Pro: $99" :x

Re: [mod] multiple content placeholder for message templates

PostPosted: 3:13pm, Tue 14 Jun, 2011
by steveoriol
I like this [mod] ;-)