MODX Community

Get a TV dropdown from a list of resources?

Is it possible to use getResources to feed a template variable dropdown list?

The front end website has a list of staff profiles for visitors to view.

In a separate back-end section of the website (like blog posts, etc.), I want to be able to pick from a dropdown of those staff members and then have the TV insert their name, photo, and a link to that staff member’s profile.

Is there a way to do this?

You can create your TV with an input type of listbox and define the getResources (or really any) snippet call in the input option values with an @EVAL Binding:

@EVAL return $modx->runSnippet('pdoResources',array('parents'=>'9','depth'=>'2','where'=>'{"template":"9"}','tpl'=>'tplsName','sortby'=>'{"pagetitle":"ASC"}','limit'=>'0','outputSeparator'=>'||'));

// notice I use pdoResources in this example
1 Like

Another way to go would be to have the drop-down list contain the user’s username, then use that username in a custom snippet that fills a Tpl chunk (userInfoChunk) with the data.

[[!UserInfo? &user_name=`[[TvName]]`  ]]
/* UserInfoSnippet */
$tpl = 'UserInfoChunk';
$username = $modx->getOption('user_name', $scriptProperties, "");

$user =  $modx->getObject('modUser', array('username' => $username));

if (! $user) {
   return 'User Not Found';
} 

$userFields = $user->toArray();

$profile = $user->getOne('Profile');

$userFields = array_merge($userFields, $profile->toArray());

return $modx->getChunk($tpl, $userFields);

The Tpl chunk (UserInfoChunk) would look just like the one you would create for pdoResources, with HTML surrounding placeholders named for the user fields.

Or use the superboxselect extra.