Hey,
So I have placed a working php script at the beggining of an included template. The aim of the script is to build vcs files on the fly based upon data stored in a weblog entry. I call it in this way:
<li>{event_location} {city}<?=CreateVcs('Test title', 'test description', "{event_location}", time(), '6:30pm');?></li>
The test data is passed as expected but the value for {event_location} doesn’t get passed to the php function. I have placed the {event_location} tag before the php function just to make sure that it does have a value.
I changed php parsing from input to output. When it was input the the actual text {event_location} got passed to the php function instead of the value it contains. When I change it to output nothing is passed to the function.
So I guess this is to do with the rendering order but I am not sure how to troubleshoot it. Any ideas anyone?
Moved to Plugins: Technical Assistance by Moderator
gabe, how are you parsing PHP in the EE template? Input or output? If you’re in an exp:weblog:entries loop, use output.
If it is input then I get the {event_location} passed as a string instead of the value. If I use output then I get a blank value.
It is within a exp:weblog:entries loop and I concluded that ouput is the right way to do it, but I can’t seem to get any value from the {event_location} variable tag this way.
Ignoring the PHP for right now.. are you getting what you expect when you echo out {event_location} in your exp:weblog:entries loop? You may want to consider writing a plugin to get back what you were going to use the PHP code for.
Yes in my exp:weblog:entries loop {event_location} current displays London which is the correct value.
Can you confirm that the PHP function is getting called at all? How are you including the function?
Yes the php function is getting called. The validation writes to a file and returns
<a href="http://foo.vcs">Add to outlook</a>
This all functions as expected but the expression engine tag parameter doesn’t get passed. The php function sits at the top of the php enabled template file.
Hmm, ok, let’s reduce this a bit. Can you try this for me, please:Put that into the same spot and see if you get any output at all.<?php $test = "{event_location}"; echo $test; ?>
Yes that snippet echos the expected value. So {event_location} works in this situation.
If I echo out the value of the function’s $location parameter I get the value:
<?php
function CreateVcs($event_title = null, $event_description = null, $location = null, $event_datestart = null, $event_time = null) {
echo $location
}
However when it gets written to a text file it reverts to {event_location} which is very strange. It even does this if I assign another variable to it first which is completely bemussing. I have deleted all created files to make sure that it is not reading a previous file.
Gabe: What if you assign the variable like:<?php $location = "{event_location}"; ?> <li>{event_location} {city}<?=CreateVcs('Test title', 'test description', $location, time(), '6:30pm');?></li>
Right the tag value does in fact get passed to the php function but it reverts to {event_location} at the point which it writes to a file. I have broken this code right down for clarity:
<?php $location = "{event_location}";?>
{event_location} - Returns London
<?php echo CreateVcs($location); ?>
<?php
function CreateVcs($location) {
echo $location; // returns London
$content .= "LOCATION;ENCODING=QUOTED-PRINTABLE: $location \n";
echo $content; // returns LOCATION;ENCODING=QUOTED-PRINTABLE: London
//NOW WE WRITE THE VCS FILE TO THE SERVER. IF THE FILE EXISTS WE OVERWRITE IT. - Added some checking
if (($fp=@fopen($filename, "w")) === FALSE) {
return null;
} else {
//NEXT WE WRITE THE CONTENT INTO THE FILE
if (@fputs($fp, $content) === FALSE) { @fclose($fp); return null; }
// Writes LOCATION;ENCODING=QUOTED-PRINTABLE: {event_location} to $filename
//FINALLY WE NEED TO CLOSE THE FILE
@fclose($fp);
$output = "<a >Add to Outlook</a>";
return $output;
}
}
In this scenario the vcs file created contains LOCATION;ENCODING=QUOTED-PRINTABLE: {event_location} instead of picking up the value. When I use an fputs it suddenly reverts to the actual string {event_location} instead of using its value. However it doesn’t do this with the variables $location or $content. I can’t see why it would be any different.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.