We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6348
    • 90 Posts
    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);
    ?>
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Do you have the PHx plugin installed?
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 6348
        • 90 Posts
        Yes
          • 28042 ☆ 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');
          ?>
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 6348
            • 90 Posts
            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?
              • 28042 ☆ 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`!]
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org