We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3039
    • 2 Posts
    please, can anybody help with the following question:
    as I know from Smarty, for example, to assign varieble I do something like $smarty->assign("placeholder", $var );
    I need some code to be executed and the result to be output in the template, so generally, where the parser and were the temlate, how to assign?
    Important! It should be done with a raw code without any GUI panels. Will be glad to see a simple example.
      • 7231
      • 4,205 Posts
      Check out the PHx plugin. http://wiki.modxcms.com/index.php/PHx
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don't know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 3039
        • 2 Posts
        still, after reading wiki, installed plugin but don’t understand were and how to assign
          • 3749
          • 24,544 Posts
          If you’re using Smarty, this is all you need:

          include('Smarty.class.php');
          
          // create object
          $smarty = new Smarty;
          
          // assign some content. This would typically come from
          // a database or other source, but we'll use static
          // values for the purpose of this example.
          $smarty->assign('name', 'george smith');
          $smarty->assign('address', '45th & Harris');
          
          // display it
          $smarty->display('index.tpl');


          index.tpl:
          <html>
          <head>
          <title>User Info</title>
          </head>
          <body>
          
          User Information:<p>
          
          Name: {$name}<br>
          Address: {$address}<br>
          
          </body>
          </html>




          index.tpl is just a text file and it can be anywhere and can be called anything.

          Usually, the first code piece above goes in the plugin and is hooked to a MODx exent (e.g. onWebPagePrerender).

          Then, in the page where you want to show the results, you just put
          $modx->invokeEvent('onWebPagePrerender');


          That triggers the plugin code which gets the smarty tpl, fills it in, and sends it to the browser.

          I’m assuming that your plugin is intended to modify the manager. If you want to modify a page in the front-end, you’d normally use placeholders rather than Smarty and just use $modx->setPlaceholder();
            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