0

I have the following code:

<script>
$(document).ready(function() {
  $(function() {
    var availableTags = [

    {model_ref}
    ];
  $( "#model" ).autocomplete({
  source: availableTags
  });
  });
 });

How can I get this to populate the input from expression engine entries?

tshepang
  • 12,111
  • 21
  • 91
  • 136

2 Answers2

1

@JamesNZ has it and this worked for me.

To avoid any weirdness with the way arrays work in javascript, I added an extra empty value to the end of the returned array, like this.

<script>
    var availableTags = [
        {exp:channel:entries channel="yourchannel" limit="10" dynamic="no"}
        "{title}",
        {/exp:channel:entries}
       "" //extra empty value here.
    ];
</script>
Community
  • 1
  • 1
0

You can do what you're after with the expressionengine channel entries tag.

<script>
var availableTags = [
    {exp:channel:entries channel="yourchannel" limit="10" dynamic="no"}
    "{title}",
    {/exp:channel:entries}
];
</script>

This will produce some javascript like:

<script>
var availableTags = [
    "First value",
    "Second value",
    "Third value",
    ... etc ...
];
</script>

The only thing is this code will have to be in a template (not a standalone JS file).

JamesNZ
  • 482
  • 5
  • 17