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

Answered PHP code in modx

    • 28042 ☆ A M B ☆
    • 24,524 Posts
    If you like, you can install pdoTools and use the Fenom parser, which is a lot closer to inline PHP code.
    https://github.com/fenom-template/fenom/blob/master/README.md

    {if $modx->user->isAuthenticated($modx->context->key)}
        <span class="comments-subscribe pull-right">
            <label for="comments-subscribe" class="checkbox">
                <input type="checkbox" name="" id="comments-subscribe" value="1" {$subscribed != '' ? 'checked' : ''} /> {$modx->lexicon('ticket_comment_notify')}
    	    </label>
        </span>
    {/if}

    https://modx.pro/components/5598-pdotools-2-0-0-beta-c-templating-fenom/

      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
      • 4172
      • 5,888 Posts
      Quote from: donshakespeare at Dec 31, 2015, 06:11 PM
      This topic has been discussed elsewhere. And there, I opted for such a function.

      There is nothing sweeeter than having the ability/freedom to mix languages ... and don't know if it will be too much for MODX to allow raw PHP in content.
      Yes, yes, I know of the school of thought that supports 'separation of logic', 'security risks' etc ... but does not freedom, at least the modern notion of it, mean, license to shoot oneself.

      There are good reasons for that separation besides clean html-markup.
      One Reason to separate logic from content is,
      you don't want content-editors to be able to run any php-code, if they are not allowed to create/edit snippets.
      Only Developers are allowed todo so.

      pdoTools with Fenom - parser enabled does allow to run php, if one needs that really.

      [Edit]
      Didn't see Susan's comment about pdoTools and Fenom
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
      • discuss.answer
        • 42562
        • 1,145 Posts
        Very nice that this option exists with pdoTools, now that's what I call flexibility!,
        although my personal practice is to always use snippets
          TinymceWrapper: Complete back/frontend content solution.
          Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
          5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
          • 51106
          • 39 Posts
          Hello again!

          I would like to inform you that I still have questions about MODX cuz it's my first time I'm using CMS(MODX).until I'm familiar with Chunks TVs Templates and so on.. but about Snippets are not clear to me and I don't understand how can I connect to my database .someone can explain me very clear or send me a nice document about how I can create a PHP page and connect it to my database .Brief create registration ,login forms and store data into own database,cuz all documents I got weren't very clear to me .

          Thank you for taking the time to consider my request, and I hope that you can assist me with this request. I appreciate your time and effort to get this done for me.
            • 51106
            • 39 Posts
            Hello again!

            I would like to inform you that I still have questions about MODX cuz it's my first time I'm using CMS(MODX).until I'm familiar with Chunks TVs Templates and so on.. but about Snippets are not clear to me and I don't understand how can I connect to my database .someone can explain me very clear or send me a nice document about how I can create a PHP page and connect it to my database .Brief create registration ,login forms and store data into own database,cuz all documents I got weren't very clear to me .

            Thank you for taking the time to consider my request, and I hope that you can assist me with this request. I appreciate your time and effort to get this done for me.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              A snippet is simply included into the MODX processing. The index.php starts MODX, and it includes all snippets and plugins like any .php file includes other .php files. So when using snippets and plugins, you have the full MODX API available - session is already started and database connection is already made.

              Seriously, you should go over the documentation here https://rtfm.modx.com/revolution/2.x/developing-in-modx/basic-development/snippets
              https://rtfm.modx.com/revolution/2.x/developing-in-modx/basic-development/snippets#Snippets-DatabaseInteractioninSnippets

              https://rtfm.modx.com/revolution/2.x/case-studies-and-tutorials/php-coding-in-modx-revolution,-pt.-i


                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