I am attempting to render a React.js component on a page template (Page.ss) in a Silverstripe CMS instance. I have the following react component:
import styles from './myComponent.module.scss';
type Props = {
pageTitle?: string;
};
const ExampleReactComponent = ({ pageTitle = 'Home'}: Props): JSX.Element => {
return (
<div className={styles['example-sync-component']}>
This is a React component. Here is a prop: <em>{pageTitle}</em>
</div>
);
};
export default ExampleReactComponent;
This renders into Page.ss (CMS template) with:
<div data-component="my-component"></div>
And displays the value of pageTitle (e.g. 'Home') correctly. But I would like to be able to do something like:
<div data-component="my-component" data-page-title="$Title"></div>
... where $Title is a variable on the Silverstripe template that will return 'Home'. How can I get the value from the template variable into the props for my react component? Thanks.