Config variables


As with language variables, Outlast Framework provides a way to separate configuration items into a nicely organized, standardized, simple key/value ini file.

Use in controllers

Config files are a bit easier to work with than language files given that there are no locales involved. The only thing you must remember is the naming convention – ini files must be placed under /conf/*.conf.ini so for your app, you’d use something like /app/conf/myapp.conf.ini.

Here’s a working example:

Use in views

Although usually it is better practice to load config files in a controller, it may sometimes be necessary to load a config from a view. You can do this with the {% config %} tag. See documentation here.

You can then use the {{#example#}} syntax in your template files. Here are some more examples:

Use in Javascript

To use config variables in Javascript, you will first need to load them up in your template with {% configjs %} (see documentation).

Attention! You should use this feature carefully as this will send your configuration variables to the client side and thus make it readable to anyone. Make sure to only load up sections for which this is not a problem (this is why {% configjs %} requires you to specify a section).

Here are some examples (this uses language variables, but the same concept applies):

Sections

You can use [section_names] to separate your language or configuration file in to multiple parts.

Here’s an illustrative example of sections for use with configuration variables:

Placeholders

Placeholders are also supported by config files and variables but are more often used for language files. See docs here.

Variable config variables

Variable variables are available in PHP $var = 'asdf'; echo $$var; and for regular ofw variables. This same concept can also be used for language and configuration variables in the OFW template system by using the keyvalue filter on the {{ofw.config}} variable – this variable returns a list of all available language and config variables.

IMPORTANT! As we’ve mentioned before – config and language variables are in the same namespace. But for variable language variables you must use {{zaj.config}} because {{zaj.lang}} actually returns the two-letter language code. Using the keyvalue filter on {{zaj.lang}} will throw a warning.

Here’s an example:

Outlast Web & Mobile Development (c) 2018 | Privacy Policy |