Reputation: 13121
I need to show author details on a page.
Here is my typoscript to get the cruser_id of the page content:
20 = CONTENT
20{
table = tt_content
select{
selectFields = cruser_id
}
renderObj = COA
renderObj{
10 = TEXT
10{
required=1
field=cruser_id
}
}
}
How to get the username associated with the cruser_id?
Upvotes: 1
Views: 4886
Reputation: 8614
As you didn't specify the context of your code, here's an example that just extends the code you provided.
20 = CONTENT
20 {
table = tt_content
select {
selectFields = cruser_id
}
renderObj = RECORDS
renderObj {
source.field = cruser_id
tables = be_users
dontCheckPid = 1
conf.be_users = TEXT
conf.be_users {
field = username
noTrimWrap = || |
}
}
}
EXPLANATION: You are fetching the content using the CONTENT
cObject and telling TYPO3 to render it as RECORDS
cObject. This object now has user's UID available as cruser_id
and can use it in its configuration using the source.field
. RECORDS
thus loads the record (with UID = cruser_id) from the be_users
table and you tell TYPO3 to render it as a TEXT
cObject. As it can be any cObject (e.g. COA), the output can be more complex, including other fields from the backend user's record.
More complex example
20 = CONTENT
20 {
table = tt_content
select {
selectFields = cruser_id, tstamp
}
renderObj = COA
renderObj {
10 = TEXT
10 {
field = tstamp
date = j/n/Y
noTrimWrap = |Last modified: ||
}
20 = RECORDS
20 {
source.field = cruser_id
tables = be_users
dontCheckPid = 1
conf.be_users = COA
conf.be_users {
stdWrap.noTrimWrap = |<br />Author: ||
10 = TEXT
10 {
field = realName
}
20 = TEXT
20 {
field = username
noTrimWrap = | (|)|
}
}
}
}
}
Upvotes: 3