Try the following:
$((printf $foo 2>/dev/null && printf '/subdir') || printf $bar)/yo.sh
Kind of minimized though.
A key aspect of this solution is to find a way to output the contents of $ foo, if any, and a simultaneous branch based on what something was in $ foo. printf without arguments is an error, and $ foo without content does not produce printf arguments. After that, everything else is easy.
printf printf, echo -n, .