Calling subcomponents

Ecpp-pages can embed other pages. These embedded pages are called subcomponents. They come in 2 variants: local and external. Local subcomponents are defined inside another component with <%def componentname> and closed with </def>. External subcomponents are normal components.

A subcomponentcall starts with <& and ends with &>. Insert the componentname between these tags. If you omit the library-part of the component, the current library is used. If the componentname is a single word, ecpp looks for a local component, which is called if found. Otherwise it is a external componentcall.

You can dynamically build componentnames, by putting a c++-expression inside brackets. This expression is evaluated on runtime and the resulting component is called. The expression can be of type (or convertable to) std::string, tnt::Compident or tnt::Subcompident.

After the componentname you can add named parameters. Put a name followed by '=' and a value. The value is either a constant string or a expression. A expression must be bracketed. If you want to pass just the same parameters your current component received, put the single word qparam into the list (actually you can pass any cxxtools::query_params-variable).

A special case are local components, which have c++-parameters. You can put a normal parameterlist just like in c++-functions after the defition (<%def>-block) after the componentname. The can only be called locally.

Just a local componentcall

<& localcomp param1="value1" &>

<& localcomp param1="value1" &>

Another local componentcall. We pass a c++-parameter.

<& localcomp_p(5) &>

<& localcomp_p(5) >

A external componentcall (localcomp "extcomp" does not exist)

<& subcomp param1="value1" &>

<& subcomp param1="value1" &>

a external componentcall

<& extcomp@extlib param1="value1" &>

<& extcomp@extlib param1="value1" &>

a external subcomponentcall

<& extcomp.subcomp@extlib param1="value1" &>

<& extcomp.subcomp@extlib param1="value1" &>

compose componentname by expression

<{ // define some variables here std::string compname = "extcomp"; std::string libname = "extlib"; }>

<& (compname + '@' + libname) param1="value1" &>

<& (compname + '@' + libname) param1="value1" &>

call component by componentidentifier

<& (tnt::Compident(compname, libname)) param1="value1" &>

<& (tnt::Compident(libname, compname)) param1="value1" &>

pass a expression as parameter

<& localcomp param1=(1+5) qparam param2="uhu"&>

<& localcomp param1=(1+5) qparam param2="uhu"&>

pass multiple values with the same name as parameter

<& localcomp param3="value1" param3="value2" param4="17" param4=(28) &>

<& localcomp param3="value1" param3="value2" param4="17" param4=(28) &> <%doc>

call subcomponents in c++-blocks

callComp("extcomp@extlib", request, reply, qparam);

<{ callComp("extcomp@extlib", request, reply, qparam); }>

<%def localcomp> <%args> param1; param2; param3[]; int param4[]; This is a local subcomponent. We got a parameter param1 with the value <$param1$>. % if (!param2.empty()) { We got param2 also. Its value is <$param2$>. % } We got <$ param3.size() $> times "param3" and <$ param4.size() $> times "param4". The values of param3 are: <{ std::copy(param3.begin(), param3.end(), std::ostream_iterator(reply.out(), ", ")); }>. The values of param4 are: <{ std::copy(param4.begin(), param4.end(), std::ostream_iterator(reply.out(), ", ")); }>. <%def localcomp_p(int i)> This is a local subcomponent with parameter. We got a c++-integer-parameter with the value <$i$>. This component can only be called locally because of c++-parameters.