I have a template with php enabled on output. However i can't get str_replace to work. See below code. If i just put {title} without any php then it works. But when i include php and place {title} inside the str_replace function, i get nothing displayed. I tried php with simple echo 'test'; an开发者_如何学Cd it worked. It's just not parsing {title} or other field tags.
{exp:channel:entries channel="one" url_title="{segment_2}"}
<?php
echo str_replace('old', 'new', '{title}');
?>
{/exp:channel:entries}
This may sound preposterous, but have you tried removing the url_title
parameter from the {exp:channel:entries}
tag to ensure the rest of your code and logic is working properly?
The following code should output the entry title of "old test" (without quotes):
{exp:channel:entries channel="channel_name" entry_id="xx" dynamic="off"}
{title}
{/exp:channel:entries}
Given the same entry title of "old test", this should output: "new test" (again, without the quotes):
{exp:channel:entries channel="channel_name" entry_id="xx" dynamic="off"}
<?php
echo str_replace('old', 'new', '{title}');
?>
{/exp:channel:entries}
This was tested successfully in a new, blank template with PHP Enabled and set to Output.
You might try embedding the template that has your PHP in it and sending the variable that way. The parsing on input/output still doesn't matter with certain elements sometimes.
精彩评论