In my twig application, I have a controller rendering a view.
This view is as follows:
{% extends ':Template/Backend:backend.html.twig' %}
{% block title_wrapper %}
{% endblock %}
{% block body %}
My code
{% endblock %}
In backend.html.twig, I have :
{% extends ':Template/base.html.twig' %}
{% block navbar %}
{% render controller ... %}
{% endblock %}
{% block sidebar%}
{% render controller ... %}
{% endblock %}
{% block body %}
{% endblock %}
Now, this page is super dynamic with many different ajax calls updating different part of the data. ReactJS seems to be the good way to make it simpler.
I understand how to put one component inside another one and build up on that. However, with content of my navbar and my sidebar depending on the content of my page, how do I make it work ?
My issues are :
Would love some help from a reactJS expert! Thanks!
Using the extends keyword, you can allow the current component to access all the component's properties, including the function, and trigger it from the child component. This example creates one component called ParentClass. jsx. ParentClass extends the component from React as React.
Symfony UX React is a Symfony bundle integrating React in Symfony applications. It is part of the Symfony UX initiative. React is a JavaScript library for building user interfaces. Symfony UX React provides tools to render React components from Twig, handling rendering and data transfers.
To set a data attribute on an element in React, set the attribute directly on the element, e.g. <button data-test-id="my-btn"> or use the setAttribute() method, e.g. el. setAttribute('data-foo', 'bar') . You can access the element on the event object or using a ref .
Take a look at this fiddle, with react-router
you can separate each page and create components, layouts and views.
ReactDOM.render(
<Router>
<Route path="/" component={AppContainer}>
<IndexRoute component={HomeView} />
<Route path="list" component={ListView} />
</Route>
</Router>,
document.getElementById('root')
);
Create two views, home
and list
, they may look like this:
class HomeView extends Component {
render() {
return (
<MainLayout
sidebarTitle="Links"
sidebar={<SidebarList />}>
Hello world! This is the HomeView!
</MainLayout>
);
}
}
Inside each view extends
from a layout and pass the properties like what component we need to be a sidebar
and a children
.
class ListView extends Component {
render() {
return (
<MainLayout
sidebarTitle="Text"
sidebar={<SidebarText />}>
<h1>List</h1>
<ul>
<li>Item</li>
<li>Item</li>
<li>Item</li>
<li>Item</li>
</ul>
</MainLayout>
);
}
}
In the layout use that properties to display the content in as you do with twig.
class MainLayout extends Component {
render() {
return (
<div>
<Navbar
title="APP"
/>
<div>
<div>
{this.props.children}
</div>
<div>
{this.props.sidebar}
</div>
</div>
);
}
}
Maybe it's a little bit confusing but you need to take a look at the fiddle, it's the closer I can do based on your example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With