We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37582
    • 65 Posts
    Hey,

    I have a plugin which includes a configuration file and what it should do is set systems settings according to these configurations.

    Simply looks like this:

    include ("myfile.php");
    
    $modx->setOption('myOption' => MY_OPTION);
    


    Now, from within any snippet I can call

     $modx->getOption('myOption');


    However, I cannot use the placeholder

    [[++myOption]]


    Just does not work, which means it is empty. I think I did not choose the right system event to register these placeholders. Which one do I choose?

    Thanks
    Chris
      • 33968
      • 863 Posts
      I'd like to know the answer to this too, have had similar issues and resorted to using a snippet to output the setting:

      [ [myOption]]
      <?php
      return $modx->getOption('myOption');
      


      Calling the placeholder uncached does not make any difference:
      [[!++myOption]]
      
        • 37582
        • 65 Posts
        Hey Lucas grin

        moreover, even
        $modx->setPlaceholder
        does not work...
          • 3749
          • 24,544 Posts
          Did you use a placeholder tag (rather than a system setting tag) when trying it with setPlaceholder()?

          [[!+myOption]]


          My guess is that when settings tags are parsed, the value is pulled directly from the DB, which isn't modified by setOption(), though setPlaceholder() really should work.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
          • System/Context/User Settings are configuration and are not really meant to be modified programmatically in real time as far as the parser is concerned. The settings are set as placeholders very early in the process, but BobRay is correct, if you overwrite the setting (which is prefixed with a single +, thus the two ++'s when referencing System Settings as placeholders) with:

            <?php
            $modx->setOption('myOption', MY_OPTION);
            $modx->setPlaceholder('+myOption', MY_OPTION);


            it should work fine, so long as it is not cached into cacheable content.
              • 3749
              • 24,544 Posts
              Cool idea. I hadn't thought of doing it that way, but to be clear, with OpenGeek's method:

               Tag: [[++myOption]]
              
              $modx->setOption('myOption', MY_OPTION);
              $modx->setPlaceholder('+myOption', MY_OPTION);
              


              I was suggesting this:

              Tag: [[+myOption]]
              
              $modx->setOption('myOption', MY_OPTION);
              $modx->setPlaceholder('myOption', MY_OPTION);
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting