Hey folks! I’m working on a TYPO3 12 project and I’m stuck. I’ve got a backend module with a checkbox, but I can’t figure out how to save its value and use it in my Fluid templates. I’ve looked everywhere but can’t find a good answer.
Here’s what I’m trying to do:
- Save the checkbox state when the user clicks ‘Save’
- Keep that value even after closing the browser
- Use the saved value in my frontend Fluid templates
I’m not sure if I should use the TYPO3 database, some config variable, or something else. What’s the best way to do this in TYPO3 12?
I’ve got my BackendController.php and Fluid template set up, but I’m lost on the saving and retrieving part. Any tips or code examples would be super helpful!
Thanks a bunch for any help you can give!
hey there! have you considered using site configuration? it’s pretty neat for storing simple settings. you could add your checkbox to a custom yaml file, then access it in your templates. curious tho, why do u need this checkbox value in the frontend? sounds like an interesting setup youve got goin on!
hey Leo_Wand, have u tried using the TYPO3 Registry? it’s perfect for this kinda thing. You can save the checkbox state like this:
$registry = GeneralUtility::makeInstance(Registry::class);
$registry->set(‘tx_yourextension’, ‘checkbox_key’, $value);
and then get it in ur fluid template with a custom viewhelper. it’ll stick around even after browser restarts. hope this helps!
In TYPO3 12, handling checkbox values from the backend for frontend use is quite straightforward. I’d recommend using the ExtensionConfiguration API for this scenario. It’s perfect for storing simple configuration values that persist across sessions.
First, define your checkbox in your extension’s ext_conf_template.txt file. Then, in your BackendController, you can save the checkbox state using the ExtensionConfiguration API:
$extensionConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class);
$extensionConfiguration->set(‘your_extension_key’, ‘checkbox_key’, $checkboxValue);
To retrieve the value in your Fluid templates, you’ll need to pass it through your controller. In your controller action, get the value:
$checkboxValue = $extensionConfiguration->get(‘your_extension_key’, ‘checkbox_key’);
Then assign it to your view and use it in your Fluid template. This method is efficient, doesn’t require direct database access, and persists across sessions.