We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26435
    • 1,193 Posts
    I have a config file that lists some placeholders that need to be set in Ditto. I figured writing a custom extender would be the way to go. What I need to do is loop through the array of config items and set placeholders for each one (the name, number, and value is variable and unknown).
    <?php
    foreach ($config['options'] as $name => $value)
    {
        $placeholders[$name] = array($value,"myPlaceholders");
    }
    ?>

    But it seems there is no way for me to pass the name as a parameter to the function myPlaceholders so that myPlaceholders will know which tv to parse, modify into form elements, then return.

    Can this (setting ditto placeholders dynamically) be done?
      Husband, Father, Brother, Son, Programmer, Atheist, Nurse, Friend, Lover, Fighter.
      All of the above... in no specific order.


      I send pointless little messages
      • 26435
      • 1,193 Posts
      I came up with a solution, but it involves modifying ditto.class.inc.php

      I changed line 309 in the "set custom placeholder" section from:
      $placeholders[$name] = call_user_func($value[1],$resource);

      to:
      $placeholders[$name] = call_user_func($value[1],$resource, $value[3]);
      By adding $value[3], It allows extender developers like me to pass an array of parameters to our functions

      My extender now looks something like this:
      <?php
      foreach ($config['options'] as $name => $value)
      {
          $placeholders[$name] = array($value,"myPlaceholders", "",array('name'=>$name, 'value'=>$value));
      }
      ?>
      

      I don’t know if there is a more elegant solution (that doesn’t involve hacking the ditto core) than this, but this is working really well for me.
        Husband, Father, Brother, Son, Programmer, Atheist, Nurse, Friend, Lover, Fighter.
        All of the above... in no specific order.


        I send pointless little messages