Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q: Is it possible to carry over the data provided to twig template in melody? #59

Open
st-schneider opened this issue Aug 31, 2018 · 4 comments
Labels

Comments

@st-schneider
Copy link

Is it possible that, if I have product information for example, that gets fed into the twig template and expected as a 'product' variable in twig, to be available in melody as well?

@pago
Copy link
Contributor

pago commented Aug 31, 2018

Not sure I understand the question. Would you like Melody to pick up on data that you've rendered on the server side using Twig/PHP automatically?

That unfortunately won't work. You'd need to serialize the data and pass it to the client side in another way, for example by doing <script>INITIAL_STATE = {{ _context | json_encode() }}</script> (making sure this is only done in a template rendered on the server side).

When rendering the template on the client side using the same data as on the server side, Melody will however be smart enough to keep the existing DOM nodes in place.

@pago pago added the question label Aug 31, 2018
@st-schneider
Copy link
Author

Is there any way to inject the context into a store automatically maybe? Where can I inject the context for my component? Only when the render function is called or when I assemble the component?
There seem to be some white spots in the documentation for this :)

@st-schneider
Copy link
Author

Wouldn't the storaging of the whole context go against the information hiding principle? Just thinking about DSGVO

@pago
Copy link
Contributor

pago commented Sep 3, 2018

We usually use redux to maintain a global state with components connecting to it (via melody-redux). Not sure how the DSGVO fits here since you'd just be transporting state from backend to frontend but wouldn't move it out of the users control.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants