I’m calling a snippet from template, that snippet make some calculations and creating placeholder:
$modx->setPlaceholder(’news_content’, $news_content);
In the same template, few lines below I call this placeholder: [+news_content+]
I noticed strange problem: if snippet is cached, i.e. сalled in template via [[snipp]], then value of placeholder is visible, and when changing page is remain (what is correct), but if not cache snippent, i.e. call it via [!snipp!] then it’s value is not visible. I use MOD X 1.04 Where can be the problem?
Template:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
</head>
<body>
[[snipp]]
[+news_content+]
</body>
</html>
Snippet:
<?php
$news_content="контент";
$modx->setPlaceholder(’news_content’, $news_content);
?>
-
☆ A M B ☆
- 24,524 Posts
Do you have the PHx plugin installed?
-
☆ A M B ☆
- 24,524 Posts
The PHx plugin eats placeholders. You’ll need to use the snippet uncached, since if it’s cached the placeholder value isn’t set until after PHx has removed the placeholder tags.
There are a few ways to work around this; I never use the PHx plugin myself, but if I must work on somebody else’s design that uses it I find the easiest is to simply wrap the placeholder in a snippet, since while the tags are destroyed, the value in the $modx->placeholders array is still available.
<?php
return $modx->getPlaceholder('news_content');
?>
Works, but! The information is deduced not there where it is established placeholder, and there, where snippet. And if at us it is a lot of placeholders?
-
☆ A M B ☆
- 24,524 Posts
Put the snippet where you would have put the placeholder.
Modify the snippet to take a parameter:
<?php
return $modx->getPlaceholder($pholder);
?>
Then call it with the placeholder name as a parameter:
[!GetPlaceholder? &pholder=`news_content`!]