We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18366
    • 14 Posts
    Hi, I’ve been asking this on ’General’ forum and perhaps that’s not the place to ask. Here’s my thread:

    http://modxcms.com/forums/index.php/topic,54382.0.html

    Usually when that happens I pickup the guitar for a while and I get the answer the next morning. Now even that isn’t working. This is totally screwed up, massively, big time!

    How is it possible to have a snippet that only contains one line:

    return $inputString;

    and that works in that it returns the value of that parameter passed in. Then as soon as you do strlen($inputString) that value is ALWAYS 8 no matter what you pass in. Is that insane or what? I mean the whole world should come to a stand still. This is a serious world problem.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      No, it’s not at all insane. If the placeholder’s value isn’t getting merged, then if your placeholder name is six characters, add the placeholder tags and you’ve got 8 characters. The only reason you would get a different result is if the placeholder value has been merged with the content containing your snippet.

      1. Call your snippet uncached [!mySnippet? &inputString=`[+myPlaceholder+]`!]; this will prevent your snippet from being parsed right away and increase the chances the placeholder tags will be replaced by the value.
      2. Make sure the snippet that sets this placeholder is called before the snippet that wants to use the placeholder

      Test:
      1. Put the placeholder tag by itself; what do you get?
      2. In your snippet, use
      return $modx->getPlaceholder['myPlaceholder'] 
      

      and see what gets returned. You might need to just pass the name of the placeholder and use this API function, especially if you have the PHx plugin installed (it eats placeholders).
        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
        • 18366
        • 14 Posts
        Many thanks for your suggestions.

        To rule out caching issues I have been calling the snippet with the uncached notation.

        The placeholder in question in my case is [+tags+] and that gets set when I click on a hyperlinked tag, which takes me to a tagged sort page with content items only containing that tag, so surely that means the snippet that sets it is being called before my snippet that attempts to use it, which is on that tagged sort page. If I just put [+tags+] into the plain content of the tagged sort page, it works in that whatever tag link I clicked on is put into the html output.

        I also attempted to use the getPlaceholder api call. Like you say I could then just pass the name of the placeholder to the snippet instead of the full `[+tags+]`. For now I hardcoded the placeholder name into the api call. The getPlaceholder call is not pulling out the value of the placeholder, it’s returning a null string. I guess that means the placeholder is not being set successfully before my snippet is invoked. That must be the cause of the problem as you say, but not sure how to go making it get set before my snippet call. May be I can do something like call another snippet from within my snippet to set it first.

        If you have implemented ditto tagged sorting of content items you can observe this problem on any site you’ve developed. On the tagged sort page [+tags+] can’t be passed to a snippet.