I got it to work by using an embedded template:
The main template:
{exp:safecracker
channel='mychannel'
url_title='{segment_3}'
return='site/success'
}
{!-- Safecracker Fields --}
{embed='site/entry_category' entry_id='{entry_id}'}
{!-- More Safecracker Fields --}
{/exp:safecracker}
The embedded template (site/entry_category):
{exp:channel:entries
channel='mychannel'
entry_id='{embed:entry_id}'
disable='member_data|pagination|custom_fields'
limit='1'
}
{categories backspace='2'}{category_name}, {/categories}
{/exp:channel:entries}
This works because embedded templates are parsed after module tags (like Safecracker). So EE loops through the Safecracker tag and performs all the functions inside it, then, when it's done, it loads the embedded template and processes the tags inside that. So the two don't interfere with each other and I get my entry's selected categories.
{selected}
variable will output the textselected="selected"
, since it looks like it's meant to be used to loop through a set of form fields.