3 <:datacomp:> and <:return:>

<:datacomp var name [named_args] [cache=no] [defer=no] [__args__]:>

Data components are like regular STML components, with these differences:

Think of a data component as a Python function. You call it with attributes instead of arguments, you write it in STML instead of straight Python, but it returns a Python object just like a Python function.

The <:datacomp:> tag is used like the <:component:> (see section 4.2, page ) tag, except for the first argument, var. var must be a string which names the local variable that will hold the return value of the data component:

<:datacomp returnObj foo.dcmp arg1="foo":>

In the above tag, the variable named returnObj will hold the object returned by data component foo.dcmp.

The <:return:> tag inside the data component tells the component to stop executing and return immediately the result of the Python expression in the tag. Examples:

<:return `someVar`:>
<:return `5`:>
<:return `{'hey': 'dude', 'i': 'made', 'a': 'dictionary'}`:>

If you forget to put a return tag in your data component, the object returned is the None object, just like a Python function that forgets to return something.

The __args__ argument works exactly like its <:component:> counterpart.

Like calling regular components from Python code, a way to get the value of a datacomponent is:

import AE.Component
val = AE.Component.callComponent(name, argdict, 	
        cache = whatever, compType=AE.Component.DT_DATA)
See section 4.2, page for valid values of whatever.

If you are in a Python data component and want to return the value of a variable foo, you'd do this:

raise ReturnValue, foo


Subsections