<p>After a bit more research, I found that there is additional data associated with the locales. <a href="https://craftcms.com/support/locale-data-from-templates" rel="nofollow noreferrer">This</a> article was of help. I was able to do this:</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" lang="{{ craft.locale }}" dir="{{ craft.i18n.getLocaleData().orientation }}"&gt;
</code></pre>

<p>to set the <code>dir</code> attribute.</p>

<p>For all other configuration data, Sam's answer works well.</p>

CC BY-SA 3.0
2017-04-04T14:37:49.620Z
2017-04-04T14:37:49.620Z
user2909019
<p>The answer is to create a custom plugin that will read the json files from the folders in the public directory, parse the json, and pull them into the template.</p>

<p>An alternative solution is to use Craft custom config files. (Not the answer you're looking for but would work very well.)</p>

<p>In <code>craft/config</code> create a file like <code>localedata.php</code> and make it something like this:</p>

<pre><code>&lt;?php

/**
 * Return an array indexed by locale code
 */
return [
    'ar' =&gt; [
        'serviceName' =&gt; 'arabic',
        'language' =&gt; 'ar',
        'textDirection' =&gt; 'rtl',
        'socialMediaButtons' =&gt; ['twitter', 'facebook'],
    ],
    'en' =&gt; [
        //...
    ],
    // etc
];
</code></pre>

<p>Then in your template you could do something like this:</p>

<pre><code>{#
    If the current locale is `ar` (Arabic) then this will set `localeData`
    from the array index "ar" in the config file
#}
{% set localeData = craft.config.get(craft.locale, 'localedata') %}
&lt;!DOCTYPE html&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" lang="{{ craft.locale }}" dir="{{ localeData.textDirection }}"&gt;
&lt;head&gt;
  ...
&lt;/head&gt;
</code></pre>

CC BY-SA 3.0
2017-04-03T22:37:02.403Z
2017-04-03T22:37:02.403Z
Sam Hernandez
<p>I'm creating a multilingual site and I'm looking to pass some additional configuration data to Twig so I can use it in my template. For example, suppose I have a configuration like this:</p>

<pre><code>{
  "serviceName":        "arabic",
  "language":           "ar",
  "textDirection":      "rtl",
  "socialMediaButtons": ["twitter", "facebook"],
  ...
}
</code></pre>

<p>I'd like to use this data to set the <code>dir</code> attribute in my template:</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" lang="{{ craft.locale }}" dir="{{ config.textDirection }}"&gt;
&lt;head&gt;
  ...
&lt;/head&gt;
</code></pre>

<p>Is there an easy way to do this?</p>

<p>My project structure looks like this:</p>

<p><img src="https://i.sstatic.net/rxRsw.png" alt="image"></p>

<p>Where each locale directory has a config file.</p>

<p>Thanks!</p>

<templating><localization><config><craft-pro><json>
Passing JSON to Twig
# Passing JSON to Twig

(Asked by: username_0 on 2017-03-30)

I'm creating a multilingual site and I'm looking to pass some additional configuration data to Twig so I can use it in my template. For example, suppose I have a configuration like this:
{
  "serviceName":        "arabic",
  "language":           "ar",
  "textDirection":      "rtl",
  "socialMediaButtons": ["twitter", "facebook"],
  ...
}

I'd like to use this data to set the dir attribute in my template:



  ...


Is there an easy way to do this?
My project structure looks like this:

Where each locale directory has a config file.
Thanks!

**Tags:** templating, localization, config, craft-pro, json


---

## 2 answers

### Answer by username_1 on 2017-04-03. Score: 5 | Accepted answer

The answer is to create a custom plugin that will read the json files from the folders in the public directory, parse the json, and pull them into the template.
An alternative solution is to use Craft custom config files. (Not the answer you're looking for but would work very well.)
In craft/config create a file like localedata.php and make it something like this:
 [
        'serviceName' => 'arabic',
        'language' => 'ar',
        'textDirection' => 'rtl',
        'socialMediaButtons' => ['twitter', 'facebook'],
    ],
    'en' => [
        //...
    ],
    // etc
];

Then in your template you could do something like this:
{#
    If the current locale is `ar` (Arabic) then this will set `localeData`
    from the array index "ar" in the config file
#}
{% set localeData = craft.config.get(craft.locale, 'localedata') %}



  ...


---

### Answer by username_0 on 2017-04-04. Score: 1

After a bit more research, I found that there is additional data associated with the locales. This article was of help. I was able to do this:



to set the dir attribute.
For all other configuration data, Sam's answer works well.


---

