mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[Theme] Documentation for theme settings
This commit is contained in:
parent
bf1aba5f0f
commit
1020b03416
2 changed files with 79 additions and 0 deletions
|
|
@ -9,5 +9,6 @@ Flexible theming system for Symfony2 applications.
|
|||
installation
|
||||
important_changes
|
||||
your_first_theme
|
||||
theme_settings
|
||||
theme_configuration_reference
|
||||
summary
|
||||
|
|
|
|||
78
docs/bundles/SyliusThemeBundle/theme_settings.rst
Normal file
78
docs/bundles/SyliusThemeBundle/theme_settings.rst
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
Theme settings
|
||||
==============
|
||||
|
||||
ThemeBundle has built-in, optional integration with `SettingsBundle </en/latest/bundles/SyliusSettingsBundle.html>`_.
|
||||
|
||||
Installation and configuration
|
||||
------------------------------
|
||||
|
||||
In order to start using settings for your themes, you should `install SettingsBundle </en/latest/bundles/SyliusSettingsBundle/installation.html>`_ first.
|
||||
|
||||
Theme settings schema
|
||||
---------------------
|
||||
|
||||
Theme settings schema should be saved in ``Settings.php`` file in your theme's main directory. The file should
|
||||
**return** an instance of ``SchemaInterface``. The example settings file looks like:
|
||||
|
||||
PHP 5
|
||||
~~~~~
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php // app/themes/AcmeTheme/Settings.php
|
||||
|
||||
use Sylius\Bundle\SettingsBundle\Schema\CallbackSchema;
|
||||
use Sylius\Bundle\SettingsBundle\Schema\SettingsBuilderInterface;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
return new CallbackSchema(
|
||||
function (SettingsBuilderInterface $settingsBuilder) {
|
||||
// define your settings here, e.g.
|
||||
$settingsBuilder->setDefault('option', 'foo');
|
||||
},
|
||||
function (FormBuilderInterface $formBuilder) {
|
||||
// define your form type here, e.g.
|
||||
$formBuilder->add('option', 'text');
|
||||
}
|
||||
);
|
||||
|
||||
.. note::
|
||||
|
||||
Do not define your custom class in the global namespace, as it may cause conflicts if there are more classes named the same.
|
||||
|
||||
PHP 7
|
||||
~~~~~
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php // app/themes/AcmeTheme/Settings.php
|
||||
|
||||
use Sylius\Bundle\SettingsBundle\Schema\SchemaInterface;
|
||||
use Sylius\Bundle\SettingsBundle\Schema\SettingsBuilderInterface;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
return new class implements SchemaInterface {
|
||||
public function buildSettings(SettingsBuilderInterface $builder)
|
||||
{
|
||||
// define your settings here, e.g.
|
||||
$settingsBuilder->setDefault('option', 'foo');
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
// define your form type here, e.g.
|
||||
$formBuilder->add('option', 'text');
|
||||
}
|
||||
}
|
||||
|
||||
Using theme settings in your templates
|
||||
--------------------------------------
|
||||
|
||||
Configured theme settings can be easily get in theme templates by using ``sylius_theme_settings()`` Twig function,
|
||||
which works just the same as ``sylius_settings('schema')`` function from vanilla SettingsBundle.
|
||||
|
||||
.. code-block:: twig
|
||||
|
||||
{% if sylius_theme_settings().showThisDiv %}
|
||||
<div>Hidden div!</div>
|
||||
{% endif %}
|
||||
Loading…
Add table
Reference in a new issue