We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33114
    • 518 Posts
    We here at MODx Russia started to gather info about MODx API functions to make it all clear of which functions exist and how they work. I guess every MODx developer would be interested in that. The current Quick Reference is good, but me personally and some other of my pals always have to search the forum on the details of practical implementation of API funcs. That is why we suggest making some kind of library (that can be later used by the founders themselves on the website) with the folowing template:

    Name:
    name of the function

    Description:
    A textual description of what a func does

    Syntax:

    Syntax of the function call - somewhat like its used in Quick Reference

    Parameters:
    a list of funcs parameters

    Example of use:
    a piece of code implementing the function
      http://modx.ru - российская поддержка MODx
      http://newscup.ru - экспериментальный проект
      http://yentsun.com - персональный сайт
      • 33114
      • 518 Posts
      Name:
      getTemplateVarOutput

      Description:
      returns an array of TV values

      Syntax:

      getTemplateVarOutput($tvname, $id, $published);

      Parameters:

      • tvname - name of the TV (TV)
      • id - id of the document of which we want the TV value
      • published - published or not only (0 or 1)


      Example of use:
      #returns the value of "tvparameter" TV for the current document
      
      $id = $modx -> documentObject['id'];
      $param = $modx->getTemplateVarOutput('tvparameter',$id);
      $output = $param['tvparameter'];
      
      return $output;
      
        http://modx.ru - российская поддержка MODx
        http://newscup.ru - экспериментальный проект
        http://yentsun.com - персональный сайт
        • 27226
        • 186 Posts
        Really cool! Please keep on going!
        The core MODx team is more busy in developing than in documenting. And that’s ok, since you cannot do both at the same time.
        So, having developers on the one end, and competent documentators on the other - that’s what makes up MODx’ success.
        The only thing I’d ask for: do not do it only in Russian! wink
          • 5058
          • 5 Posts
          Name:
          parseChunk

          Description:
          returns a chunk with any placeholders inside it populated with your own values


          Syntax:
          parseChunk($chunkName, $chunkVars, $prefix, $suffix);

          Parameters:

          * chunkName - name of the chunk
          * chunkVars - an associative array of variables
          * prefix & suffix- the strings which wrap around any placeholders in the chunk
          (defaults to {placeholder} , NOT {+placeholder+} !!)

          Example of use:

          if we have a chunk called ’anecdote_chunk’, like this:

          <strong>The tramp made friends with a {+colour+} {+smell+} {+beast+}.</strong>
          <img src='images/{+colour+}_{+smell+}_{+beast+}.jpg'>
          


          Then your snippet can access and populate the chunk...

          $vars=array();
          $vars['beast']='pig';
          $vars['colour']='yellow';
          $vars['smell']='cheesy';
          $output = $modx->parseChunk('anecdote_chunk', $vars,  '{+',  '+}'  );
          return $output;
          


          Notes
          parseChunk makes use of $modx->getChunk($chunkName) which you might find more useful