We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33983 ☆ A M B ☆
    • 181 Posts
    I am using Revolution 2.1 RC3, but I don’t know if this is version specific or it I am doing something wrong.

    What I am doing
    I have a snippet which is calling on modResource to get the content of that resource, called commMemberProfile. The resource content can have everything that a normal resource can have and I have a default snippet in the content area called commMember. commMember has a call to $modx->regClientStartupHTMLBlock($modx->getChunk($head, $data)) which creates some CSS.

    The error or unexpected results.
    The page displays correctly the first time after I save the resource where commMemberProfile is in the content. But the second and each additional time I load the page the CSS that is created by commMember, which is called via the processed modResource, does not show up. Note commMember works perfect when it is called directly not via a processed method.

    Relevant code of commMemberProfile:
    <?php
    $member = $modx->getObject('commUserProfile', $c);
    
    if ( is_object($member) ) {
        $member_data = $member->toArray();
        $profile_ext = $member->getOne('commMember');
        $profile_data = $profile_ext->toArray();
        // merge the data into an array
        $member_data = array_merge($member_data,$profile_data);
    } else {
        return '<p>Member not found.</p>';
    }
     
    $modx->setLogTarget('HTML');
    if ( $member_data['profile_resource_id'] > 0 ) {
        $modx->setPlaceholder('contact_resource_id', $contact_resource_id);
        
        $modx->setPlaceholders(array('contact_resource_id', $contact_resource_id));
        //$resource = $modx->getObject('modResource', array('id', $member_data['profile_resource_id']) );
        $output = 'Get Resource';
        $criteria = $modx->newQuery('modResource');
        $criteria->where(array('id'=>$member_data['profile_resource_id'],));
        $resource = $modx->getObject('modResource',$criteria);
    }
    if ( is_object($resource) ) {
        // get the content and then process it so snippets and plugins work
        // Load into a chunk to process: http://modxcms.com/forums/index.php/topic,57074.0.html
        $chunk = $modx->newObject('modChunk');
        $chunk->setContent($resource->get('content'));
        // setProperties  http://api.modxcms.com/modx/modElement.html#methodsetProperties
        $chunk->setProperties(array('contact_resource_id', $contact_resource_id));// this does not seem to work
        $chunk->setCacheable(false);
        $output =  $chunk->process(array('contact_resource_id', $contact_resource_id));
        
    } 
    return $output;
    ?>
    

    Why I am creating redundancy
    If this helps I will explain why I am making this upfront extra work for myself. We have many faculty that have only one profile page, but many faculty belong to numerous departments. I want their profile pages to appear within each department pages with that departments template options. I don’t want to create lots of profile pages because they will quickly become out of sync with each other. Hope that makes sense.

    Any help you can offer would be great, thanks.
      • 33983 ☆ A M B ☆
      • 181 Posts
      Fixed
      Not sure why but after I added a few lines in my code, it now works as expected and the code was nothing about cache.

      The code
      <?php
      $member_id = $modx->getOption('member_id', $scriptProperties, 0);
      if ( isset($_REQUEST['member_id']) && is_numeric($_REQUEST['member_id']) ){
          $member_id = $_REQUEST['member_id'];
      } 
      /* I added this elseif and this is how I send the id like page.html?staffid=330 */
      elseif ( isset($_REQUEST['staffid']) && is_numeric($_REQUEST['staffid']) ){
          $member_id = $_REQUEST['staffid'];
      }
      ?>