<p>Just use a variable that has the same keys as the entry model will have.</p>

<pre><code>{% set entries = [{title: 'hello', ...}, {title: 'hello2', ...}] %}

{% for entry in entries %}
    {# stuff #}
{% endfor %}
</code></pre>

<p>Then, when you want to move to using the database, just switch what  <code>entries</code> is set to:</p>

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

<p>That way the template will still look exactly the same.</p>

CC BY-SA 3.0
2017-04-24T10:02:15.010Z
2017-04-24T10:02:15.010Z
megatrond
<p>I'm not 100% sure I'm following what you're going for, if you want to access the array values of the <code>titel</code> property in the <code>service</code> variable, you'd do so like:</p>

<p><code>service.title[0]</code>, which would equal <code>hallo</code> and <code>service.title[1]</code>, which would equal <code>hallo2</code>.</p>

<p>So would look like:</p>

<pre><code>{% for entry in craft.entries.section(service.title[0]) %}

  &lt;p&gt;{{ entry.titel }}&lt;/p&gt;

{% endfor %}
</code></pre>

CC BY-SA 3.0
2017-04-25T14:47:54.550Z
thanks a lot brad, i think my question was a bit confusing.
HendrikEng
CC BY-SA 3.0
2017-03-24T18:45:47.193Z
2017-04-23T23:07:25.870Z
2017-04-23T23:07:25.870Z
Brad Bell
<p>I am trying to use Twig methods/loops while working on a design/template. To avoid touching the CP or the DB i did set variables directly in the template, like : </p>

<pre><code>{% set service = 
  { 
    'titel': 
      [
        'Titel1', 
        'Titel2'
      ],
  }
%}

{% for i in 0..1 %}
  &lt;p&gt;{{ service.headerQuote }}&lt;/p&gt;
{% endfor %}
</code></pre>

<p>It would be much better to be able to use the standard Craft methods, so if I move from templating/designing towards the DB i wouldn't have to touch the methods in my markup.  Unfortunately, I can't make it work... I tried:</p>

<pre><code>{% set service = { titel: 
                   [ 
                     'hallo',
                     'hallo2' 
                    ]
                  } 
                %}

{% for entry in craft.entries
      .section('service') %}

      &lt;p&gt;{{ entry.titel }}&lt;/p&gt;

{% endfor %}
</code></pre>

<p>I tried to set the service entry to craft.entries.section('service') but that doesn't work as well... what am I missing?</p>

<p>Is it even possible to overwrite Craft variables in the markup?</p>

<templating><variable>
Set Craft variables in the markup
# Set Craft variables in the markup

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

I am trying to use Twig methods/loops while working on a design/template. To avoid touching the CP or the DB i did set variables directly in the template, like : 
{% set service = 
  { 
    'titel': 
      [
        'Titel1', 
        'Titel2'
      ],
  }
%}

{% for i in 0..1 %}
  {{ service.headerQuote }}
{% endfor %}

It would be much better to be able to use the standard Craft methods, so if I move from templating/designing towards the DB i wouldn't have to touch the methods in my markup.  Unfortunately, I can't make it work... I tried:
{% set service = { titel: 
                   [ 
                     'hallo',
                     'hallo2' 
                    ]
                  } 
                %}

{% for entry in craft.entries
      .section('service') %}

      {{ entry.titel }}

{% endfor %}

I tried to set the service entry to craft.entries.section('service') but that doesn't work as well... what am I missing?
Is it even possible to overwrite Craft variables in the markup?

**Tags:** templating, variable

---

## 2 answers

### Answer by username_1 on 2017-04-24. Score: 2 | Accepted answer

Just use a variable that has the same keys as the entry model will have.
{% set entries = [{title: 'hello', ...}, {title: 'hello2', ...}] %}

{% for entry in entries %}
    {# stuff #}
{% endfor %}

Then, when you want to move to using the database, just switch what  entries is set to:
{% set entries = craft.entries.section('service') %}

That way the template will still look exactly the same.


---

### Answer by username_2 on 2017-03-24. Score: 1

I'm not 100% sure I'm following what you're going for, if you want to access the array values of the titel property in the service variable, you'd do so like:
service.title[0], which would equal hallo and service.title[1], which would equal hallo2.
So would look like:
{% for entry in craft.entries.section(service.title[0]) %}

  {{ entry.titel }}

{% endfor %}

> **Comments:**
> **username_0**: thanks a lot brad, i think my question was a bit confusing.  

---

