[TYPO3-mvc] CObjectViewHelper
Bastian Waidelich
bastian at typo3.org
Thu Oct 29 12:52:43 CET 2009
Fernando Arconada wrote:
Hi Fernando,
> Anyone has examples about cobjectViewHelper? when is the constructor
> called?
The constructor is there mostly to allow us to do some dependency
injection in the unit tests.
When used in a Fluid template, the constructor will be called without
any arguments - But you shouldn't have to care about this anyways.
Here a simple example:
Imagine you have following cObject anywhere in your TypoScript setup:
lib.myObject = COA
lib.myObject {
10 = TEXT
10.current = 1
10.case = upper
}
in your template you'll write
<f:cObject typoscriptObjectPath="lib.myObject">Hello world</f:cObject>
This should output
HELLO WORLD
But you could also use arrays or objects as input:
in your TS setup:
lib.customerRenderer = COA
lib.customerRenderer {
10 = TEXT
10.field = firstName
20 = TEXT
20.field = lastName
}
and
<f:cObject
typoscriptObjectPath="lib.customerRenderer">{customer}</f:cObject>
with the "currentValueKey" attribute you can specify which property of
the object (respectively which key of the array) will be available as
current value of the CObject:
Taken the TS setup from above:
lib.myObject = COA
lib.myObject {
10 = TEXT
10.current = 1
10.case = upper
}
You could now write:
<f:cObject typoscriptObjectPath="lib.myObject"
currentValueKey="firstName">{customer}</f:cObject>
And it should output the first name of the customer object upper cased.
BTW: with the latest revision, you can also use this view helper with
the inline notation: {f:cObject(typoscriptObjectPath: 'lib.myObject',
data: customer, currentValueKey: 'firstName')}
Note: I didn't test these examples, if you encounter any problems, let
us know!
You might want to check out the "viewhelpertest" extension from
https://svn.typo3.org/TYPO3v4/CoreProjects/MVC/viewhelpertest/
It comes with a lot of example use cases and we're trying to keep it up
to date.
Best,
Bastian
More information about the TYPO3-project-typo3v4mvc
mailing list