1
votes

I have a snippet which gets document IDs from the DB.

I want to out put these in a menu with Wayfinder but am having trouble getting it to work. Does anyone know the correct way of placing a PHP var within Wayfinder? Tried this but no luck:

echo '[[Wayfinder? &includeDocs=`' . $docid . '`]]';

(PS: using Revo)

EDIT: Added more code

In a nut shell, my code gets a logged in users id from sessions and finds thier access group. Ultimate goal is to display links to resources that are within their access group. This is the later part of the snippet where I have got the appropriate resource IDs and just need to out put them.

//RETRIEVE DOCUMENT GROUPS RELATED TO ACCESS GROUPS
          $docgroups = "SELECT * FROM `modx_document_groups` WHERE `document_group` = '$target' ";

          $docstmt = $modx->query($docgroups );              

          while ($docrow = $docstmt->fetch(PDO::FETCH_ASSOC)) {
          $docid = $docrow['document'];            

          echo '[[Wayfinder? &startId=`0` &includeDocs=`' . $docid . '`]]';

          }//END
2

2 Answers

2
votes

In modx, your snippets must return a value to access it in chunks/templates etc. This is one way:

//MySnippet
<?php
// logic
$docIDs = array(1, 2, 23, 17);
return implode(',', $docIDs);

and then your wayfinder call uses the snippet:

 // wayfinder call
[[!Wayfinder? &includeDocs=`[[!MySnippet]]`]]

// is the same as:
[[!Wayfinder? &includeDocs=`1,2,23,17`]]
1
votes

The right way to do this at Modx Revolution :

$c = $modx->newQuery('modResourceGroupResource');
$c->where(array( 'document_group' => $target ));
$docs = $modx->getCollection('modResourceGroupResource', $c);

$docids = array();
foreach($docs as $doc) {
    $docids[] = $doc->get('document');
}

$output = $modx->runSnippet('Wayfinder',array(
    'startId' => 0,
    'includeDocs' => implode(',', $docids);
));

return $output;