If this tutorial is helpful to you, you can donate some money to the tutorial author via Paypal.

Sometimes you need a couple of configuration parameters for your project. In TYPO3 most of this settings are done via flexforms or TypoScript settings.

In FLOW3 there is a file called Settings.yaml. There you can add your settings for your project. There are also different contexts available. So you can add the Settings.yaml file directly in the configuration folder, or you choose a sub folder. Available contexts are Development, Production and Testing. Making usage of the different contexts makes a lot of sense if you want to deploy your project from development to production and if you have different settings for development and production.

For example, on my twitcode.org project I use OAuth for the connection to twitter. So I set the credentials for twitter in my Settings.yaml file and I have different credentials for development and production. Since the context is set in my vhost configuration, I don't have to take care of switching this. As soon as my files are on the live server, FLOW3 is automatically picking the right settings in dependency of the current context.

For this example we put the Settings.yaml in the root of the configuration folder and just add the lines below.
Layh.Events/Configuration/Settings.yaml 

Layh:
  Events:
    headline: 'FLOW3 Tutorial'

Inject the settings

To make the settings available in our controller we add a injectSettings function and set the settings.

After that the settings are available in our $this->settings array.

In our indexAction you can see how to access the settings and use them.
Layh.Events/Classes/Controller/EventController.php 

/**
 * @var array
 */
protected $settings;
 
/**
 * Inject settings
 *
 * @param array $settings
 * @return void
 */
public function injectSettings(array $settings) {
    $this->settings = $settings;
}
 
 
/**
 * index action
 *
 * @return void
 */
public function indexAction() {
 
    // set headline if set in settings
    if (isset($this->settings['headline'])) {
        $headline = $this->settings['headline'];
    }
 
    $this->view->assign('headline', $headline);
 
}

Using the settings in Fluid

If you just want to use the settings in your Fluid template, you don't have to inject or assign the settings to you view. You can just access them via Fluid using {settings.youSetting}
Layh.Events/Resources/Private/Templates/Event/Index.html 

{settings.headline}

Was this tutorial helpful? So, you can donate some money to the tutorial author via Paypal.