We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31601
    • 57 Posts
    Right-0

    I use a custom placeholder constantly in building sites that are multi-lingual so I can avoid using sessions on simple sites or sites that I know will be in corporate environments where there is an off-chance possibility that IT policies disable cookie use. This way I don’t have to rely on sessions or cookies to track language for site display.

    This always seems to work a charm, but I ran into a problem today where I had to use a session variable because I’m using a jquery ajax load for document content, and the document that gets loaded via ajax runs a snippet that requires reading the placeholder (using $i=$modx->getPlacholder(’language’); ).

    I’m using a copy of the minimal template (just using the [*content*] placeholder, without any other html markup such as html, head, body tags) and when this document was called via the ajax load, the placeholder was NOT being read. The document also contains a call to Ditto- that ran perfectly with $modx->runSnippet. Only the placeholder wasn’t available. I just added a session variable into my language management snippet and I was then able to read a variable for language without problems- however, I’d like to know for future reference the mechanism of custom placeholders in modx (are they stored in the DB, are they superglobal PHP variables, etc), and if a template requires more markup to be able to access the custom placeholder. As well, are custom placeholders tied to specific templates? I didn’t think so, but maybe I’m wrong.

    BTW, this is EVO 1.03.

    thanks in advance to anyone who can shed some light on the usage of custom placeholders!
    • Placeholders are only available in the scope of a single request. They are not persisted in any way other than in the DocumentParser object for the duration of a request.
      • You’ll need to pass that language value on to the back-end processor as a parameter in your AJAX call.
          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