Email Placeholder Stopped Working
6 posts by 3 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: January 9, 2015 (RSS)
By Perchpole - January 8, 2015
Hello, All -
This is an odd one! For some reason one of the placeholders in my email template has stopped working.
#server.http_host#
I think this is a global placeholder. It was a way of showing the site URL at the foot of an email - but for some reason it doesn't work any more.
:0S
Perchpole
By gkornbluth - January 8, 2015 - edited: January 8, 2015
Certainly is an odd one.
I'll think on it.
Are there other placeholders that work
Here's the (rather long) recipe from my CMSB Cookbook http://www.thecmsbcookbook.com that addresses variables in a text box just in case it helps.
INCLUDING VARIABLES IN THE CONTENTS OF A TEXT BOX
User zip222 wanted to include a variable in a text box field so that the contents of the textbox could be customized.
Here’s what Jason Sauchuk from Interactive Tools suggested:
Welcome to the Online Student Log-in for the *school_name* This section of our website provides links...
You can then replace *school_name* when you are outputting your content.
(Note: In this example, we're assuming that the values for *school name* is in an editor called "school_record" and the
text field is a field called "content" in a table called" your_table".)
For a list page:
_____ code ________________________________________________
<?php echo str_replace('*school_name*',$schoolRecord['title'],$record['content']);?>
__________________________________________________________
For a detail page the code would change to:
_____ code ________________________________________________
<?php echo str_replace('*school_name*',$schoolRecord['title'],$your_tableRecord['content']);?>
__________________________________________________________
Jason explained:
In this code, the sub string *school_name* is replaced in the string $record['content'] with the variable
$schoolRecord['title']
__________________________________________________________
__________________________________________________________
Another way to look at this is:
If you place a variable called *var1* in a target text box field called target_field in a table called target_table
And your source for *var1* is in a text box field called source_field in a table called source_table
Then the code in the body of the viewer where you want to display the composite would be:
_____ code ________________________________________________
<?php echo str_replace('*var1*',$source_tableRecord['source_field'],$target_tableRecord['target_field']);?>
__________________________________________________________
__________________________________________________________
Another scenario:
The detail page for a series of event listings contained a PayPal payment link that redirected to a thank you page after
successful payment.
In my thank you page I wanted the text field to include the name of the event that was paid for.
I inserted *var1* in my thank you pages' target text field as above and inserted the above code in the body of my thank
you page.
Then, I added:
NOTE:
_____ code ________________________________________________
?<?php echo $source_tableRecord['num'] ?>%23
__________________________________________________________
to the return URL in my PayPal button code. The %23 (URL-encoding for #) inserts a # after the record number that
separates the transaction data (if any) from the record number so it will render correctly, (of course with my own
source_table name inserted)
__________________________________________________________
__________________________________________________________
And another scenario:
I had a series of variables that I wanted to insert in the thank you page above, and some of them were dependent. IE
they shouldn't show unless there was data in a specific field.
For example, if there was no special venue for an event, I didn't want to show the special venue name, address, or
warning in the thank you page.
With some help from Jason Sauchuk from Interactive Tools, here's what I came up with.
In the viewer:
_____ code ________________________________________________
<?php
$event_start_date = date("l, M jS, Y", strtotime($learning_centerRecord['event_start_date'])) ;
$special_location = "";
if (@$learning_centerRecord['special_event_location_name']) {
$special_location = "<b>Special Location: ".$learning_centerRecord['special_event_location_name']."</b>\n"."<br
/>\n".$learning_centerRecord['special_event_location_address']."<br />\n";
}
$placeHolders = array("*var1*", "*var2*", "*var3*", "*var4*", "*var5*", "*var6*" );
$replaceWith = array($learning_centerRecord['event_title'], $learning_centerRecord['event_fee'], $event_start_date,
$learning_centerRecord['event_times'], $learning_centerRecord['event_description'], $special_location);
echo str_replace($placeHolders, $replaceWith, $common_informationRecord['learning_center_thank_you_1']);
?>
__________________________________________________________
And in the Text Field ('learning_center_thank_you_1)
NOTES: The the ."<br />\n" after Special Location:puts that text on its own line on the finished page. The <br /> after
the special_event_location_name is because the address is a multi line entry. The extra ."<br />\n" at the end allows
you to remove the blank line after *var6* below, and have it appear only when there's a "special_event_location_name"
_____ code ________________________________________________
Congratulations, you're all signed up for <b>"*var1*"</b>
on <b>*var3*, from *var4*</b>
*var6*
We suggest that you arrive at least 15 minutes early so that you can get to know some of the other attendees.
Here's a copy of the description of this event.
*var5*
See you there...
__________________________________________________________
__________________________________________________________
Another scenario:
I used this approach to insert a link and an image called "image1" from a single record editor called "graphics" in a
text box called "content" in the table "my_table" with the following code.
In the contents of the text box where I wanted the link to appear, I inserted:
_____ code ________________________________________________
<a href="my_URL.com/my_page.php"><img src="*variable*"></a>
__________________________________________________________
And in the page code for my list page (in the foreach loop)
_____ code ________________________________________________
<?php $myImage = $graphicsRecords[0]['image1'][0]; ?>
<?php echo str_replace('*variable*',$myImage['thumbUrlPath'],$record['content']);?>
__________________________________________________________
And for my detail page.
_____ code ________________________________________________
<?php $myImage = $graphicsRecords[0]['image1'][0]; ?>
<?php echo str_replace('*variable*',$myImage['thumbUrlPath'],$my_tableRecord['content']);?>
__________________________________________________________
Don't forget to include load records calls for both editors at the top of your viewers
__________________________________________________________
__________________________________________________________
I asked Jason how to include more than one variable (text, links or images) in the same text box and he said:
str_replace is a php function (http://ca3.php.net/str_replace) that searches for one string inside another and replaces
all instances of that string.
So, if you want to be able to insert more than 1 piece of text into a string, you'll need more placeholders (*var1*,
*var2*, *var3*, etc). The actual name of the placeholder is irrelevant, but you should choose something that is unlikely
to appear naturally in the text.
You can also use arrays with str_replace. For example:
_____ code ________________________________________________
<?php
$placeHolders = array("*var1*", "*var2*", "*var3*");
$replaceWith = array($link1, $image1, $link2);
echo str_replace($placeHolders, $replaceWith, $record['content']);
?>
__________________________________________________________
In this example, str_replace will look in $record['content'] and replace all instances of *var1* with $link1, all
instances of *var2* with $image1, and all instances of *var3* with $link2.
Best,
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
By Perchpole - January 8, 2015
Hi, Gerry -
Thanks for your input. The other email placeholders are fine. It's just #server.http_host# that has stopped working.
It's not important - I just want to know why?!
I thought this placeholder was hardwired into the CMSB code - which suggest there's something else going on that perhaps I should be aware of.
:0/
Perch
By claire - January 9, 2015
Hey Perch
That variable comes from the $_SERVER global, it's not always available. Has it stopped working completely or just in a few instances?
Has anything about the server changed recently?
Claire Ryan
interactivetools.com
Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
By Perchpole - January 9, 2015
Hi, Claire -
I think it's stopped completely. Other placeholders are working fine.
Curiously, I have an identical copy of the same site on the same server. In that instance the placeholder is correctly!
What could have affected it?
I'm just worried it could be a sign of something more serious.
:0(
Perch
By claire - January 9, 2015
I'd definitely recommend checking your server to see if anything has changed. Maybe ask your host if they've made any updates?
Claire Ryan
interactivetools.com
Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/