<p>This is how I did it:</p>

<pre><code>&lt;script type="text/javascript"&gt;
     var bpDetails = {
         buttonText: '{{ siteOptions.buttonText }}',
         descriptionText: '{{ siteOptions.descriptionText }}'
     };
&lt;/script&gt;
</code></pre>

<p>I was then able to access this variable in my AngularJS portion and check </p>

<pre><code>if(bpDetails)
  vm.bpDetails = bpDetails; 
</code></pre>

<p>That way I was able to use the craft content stored into a JS object to display/manipulate in the view.</p>

CC BY-SA 3.0
2016-07-07T12:48:46.343Z
2016-07-07T12:48:46.343Z
Exziled
<p>One way to go about this is to use the JSON Expand plugin from <a href="https://familiar-studio.com/" rel="nofollow">Familiar Studio</a>:</p>

<p><a href="https://github.com/familiar-studio/craft-json-expand" rel="nofollow">https://github.com/familiar-studio/craft-json-expand</a></p>

<p>It's pretty easy to use:</p>

<pre><code>{% set hpContent = craft.entries.section('homepageContent').find() %}
</code></pre>

<p>Then you can just grab the data you need from the json object like:</p>

<pre><code>&lt;script type="text/javascript"&gt;
    var homepageContent = hpContent|json_expand|raw }};
    console.log({{ hpContent|json_expand|raw }});
&lt;/script&gt;
</code></pre>

<p>One caveat I've found though is that content in Rich Text editors doesn't output.  If you're just using simple text fields, then you should be fine.  If you do need something Rich Text-like, you could use Craft's <code>|markdown</code> filter on data from a simple text field.</p>

CC BY-SA 3.0
2016-07-05T10:19:21.163Z
2016-07-05T10:19:21.163Z
Ryan
<p>I want to put a few simple text fields into Craft CP and then be able to retrieve them with JavaScript.</p>

<p>What is the best way to structure this in Craft? I'd like to be able to create/edit an "entry" and then do something like this:</p>

<pre><code>&lt;script type="text/javascript"&gt;
    var homepageContent = {{ craft.entries.homepageContent }};
    console.log('details: ', homepageContent);
&lt;/script&gt;
</code></pre>

<p>The homepage content entry in Craft needs to have ~2-3 fields attached to it. </p>

<p>I created the 3 fields that I think I will need to be editable on the homepage. Now I'm unsure how to get these tied to be able to enter an "entry" into something like a Homepage Content group?</p>

<templating><entries><entries-field>
Put simple content into Craft and grab it in JavaScript
# Put simple content into Craft and grab it in JavaScript

(Asked by: username_0 on 2016-07-01)

I want to put a few simple text fields into Craft CP and then be able to retrieve them with JavaScript.
What is the best way to structure this in Craft? I'd like to be able to create/edit an "entry" and then do something like this:


The homepage content entry in Craft needs to have ~2-3 fields attached to it. 
I created the 3 fields that I think I will need to be editable on the homepage. Now I'm unsure how to get these tied to be able to enter an "entry" into something like a Homepage Content group?

**Tags:** templating, entries, entries-field

---

## 2 answers

### Answer by username_0 on 2016-07-07. Score: 1 | Accepted answer

This is how I did it:


I was then able to access this variable in my AngularJS portion and check 
if(bpDetails)
  vm.bpDetails = bpDetails; 

That way I was able to use the craft content stored into a JS object to display/manipulate in the view.


---

### Answer by username_1 on 2016-07-05. Score: 2

One way to go about this is to use the JSON Expand plugin from Familiar Studio:
https://github.com/familiar-studio/craft-json-expand
It's pretty easy to use:
{% set hpContent = craft.entries.section('homepageContent').find() %}

Then you can just grab the data you need from the json object like:


One caveat I've found though is that content in Rich Text editors doesn't output.  If you're just using simple text fields, then you should be fine.  If you do need something Rich Text-like, you could use Craft's |markdown filter on data from a simple text field.


---

