We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14883 ā˜† A M B ā˜†
    • 450 Posts
    I want to write something like this:
    $user = $modx->user;
    $profile = $user->getOne('Profile');
    //$fields = array('email', 'fullname');  // I don't want to have to guess/know the fieldnames like this
    $fields = $profile->fieldNames;  // this doesn't work, but I don't know what *will* work
    foreach ($fields as $f) { 
      $modx->setPlaceholder($f, $profile->get($f));
    }
    


    It looks like $modUserProfile::fieldNames should have what I want, but maybe I’m reading the documentation wrong and/or going about it the wrong way?
      • 22303 MODX Staff
      • 10,725 Posts
      Some examples:

      <?php
      // set entire profile as placeholders
      if ($modx->user->getOne('Profile')) {
          $modx->toPlaceholders($modx->user->Profile->toArray());
      }
      
      // set specific fields as placeholders
      if ($modx->user->getOne('Profile')) {
          $modx->toPlaceholders($modx->user->Profile->get(array('email', 'fullname')));
      }
      ?>