Forum Discussion

KPNOnline's avatar
KPNOnline
Mentor
10 years ago

Pass object or array between 2 custom components

I have a custom component, a 'controller'.. Thats manages some data for an interactive header.

 

This component does not render, but only passes the data to a 'child' component (view), and the view will render whatever he gets from the controller.

 

 But how can I pass the data from the 'parent' view to the childview..

 

In my parentView I set my data and call my 'sub' view like this:

 

<#assign slides=[1,2,3,4,5,6,7] />

<@component id="sybView" slides=slides />

 

But how can i get to that data in the subView???? 

 

This doesn't work:

 

${env.context.component.getParameter('slides')}

 

4 Replies

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)
    10 years ago

    Hi KPNOnline

     

    have you tried to pass your parameter as a string value instead? What error are you getting?

     

    Thanks,

  • KPNOnline's avatar
    KPNOnline
    Mentor
    10 years ago

    Hi PaoloT,

     

    thanks for the reply. It works with a string indeed, but Objects and Arrays do not pass.. Is there a way for that? Without endpoints + macro's? Or am I supposed to 'stringify' an json object and parse it again back in the receiving view?

     

    Thanks!

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)
    10 years ago

    Hi KPNOnline

     

    I have seen in the past issues in passing arrays. However it should be possible to pass some objects. Maybe you also want to have a look to these resources - I am not entirely sure around the limitations other than what is mentioned in the documentation.

     

    In your specific case, as you are passing an array of IDs, you could always use a workaround: that is, join the sequence into a string, pass it to the component as a string, and then explode it into a sequence using split . It may do the trick for you.

     

    Kind Regards,

     

  • KPNOnline's avatar
    KPNOnline
    Mentor
    10 years ago

    Hi PaoloT

     

    Thanks for the tips. Im going to have a look at them.

     

    In the real life examples its going to be quite a big multilayer object, but dividing it in arrays could indeed be solution.