<p>It looks like you have 2 questions here?</p>
<p>1- why not run them through a loop? it will then only display the amount of images you have.</p>
<p>eg;</p>
<pre><code>{% for images in entry.car_photos.all() %}
&lt;div class=&quot;cSlider__item&quot;&gt;
  &lt;img class=&quot;is-rounded&quot; src=&quot;{{ image.url }}&quot;&gt;
&lt;/div&gt;
{% endfor %}
</code></pre>
<p>Second issue (probably should have had a second question for this).</p>
<p>You are pulling all of the entries out that have that status set and then displaying your if div if the query has succeeded. As long as there is any entry with that status that command will ALWAYS succeed.</p>
<p>In pseudocode what you are currently doing is this</p>
<ul>
<li>Get all of the entries with a status of 2</li>
<li>if you got all of the entries with a status of 2 entries show this div</li>
</ul>
<p>What you need to do is loop through your entries and display that div IF that status  matches.</p>
<p>Example:</p>
<pre><code>{% for entries in craft.entries.all() %}
  
{% if entries.Availability_Status('1') %}
&lt;div style=&quot;float: right; display: inline-block; margin-top: -1rem;&quot;&gt; &lt;div class=&quot;buttons&quot;&gt;&lt;button class=&quot;button is-warning is-normal&quot;&gt;Еще не объявлено&lt;/button&gt;&lt;/div&gt;&lt;/div&gt;
{% endif %}

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

CC BY-SA 4.0
2021-07-27T01:05:55.710Z
2021-07-27T01:05:55.710Z
Mark Lloyd
<p>I have two problems with CraftCMS :(</p>
<p>First one - I want to make images gallery and now using something like this:</p>
<pre><code>     {% set image = entry.car_photos[0] %}
{% if image %}&lt;div class=&quot;cSlider__item&quot;&gt;
     &lt;img class=&quot;is-rounded&quot; src=&quot;{{ image.url }}&quot;&gt;
&lt;/div&gt;{% endif %}
        {% set image = entry.car_photos[1] %}
{% if image %}&lt;div class=&quot;cSlider__item&quot;&gt;
     &lt;img class=&quot;is-rounded&quot; src=&quot;{{ image.url }}&quot;&gt;
&lt;/div&gt;{% endif %}
    {% set image = entry.car_photos[2] %}
{% if image %}&lt;div class=&quot;cSlider__item&quot;&gt;
     &lt;img class=&quot;is-rounded&quot; src=&quot;{{ image.url }}&quot;&gt;
&lt;/div&gt;{% endif %}
</code></pre>
<p>The problem is that if the third image doesn't exist - I get the error. How can I make it work?</p>
<p>And second problem... I have field with my entries with number in it. So if the entry have that field with value &quot;2&quot; - I want to show text &quot;On sale&quot;, if value &quot;1&quot; - I want to have &quot;Out of stock&quot;. I tried with documentation but it doesn't help me... I tried something like this:</p>
<pre><code>{% set soon = craft.entries()
    .Availability_Status('2')
    .all() %}
{% if soon %}
&lt;div style=&quot;float: right; display: inline-block; margin-top: -1rem;&quot;&gt; &lt;div class=&quot;buttons&quot;&gt;&lt;button class=&quot;button is-warning is-normal&quot;&gt;Еще не объявлено&lt;/button&gt;&lt;/div&gt;&lt;/div&gt;
{% endif %}

{% set out = craft.entries()
    .Availability_Status('1')
    .all() %}
{% if out %}
&lt;div style=&quot;float: right; display: inline-block; margin-top: -1rem;&quot;&gt; &lt;div class=&quot;buttons&quot;&gt;&lt;button class=&quot;button is-warning is-normal&quot;&gt;Еще не объявлено&lt;/button&gt;&lt;/div&gt;&lt;/div&gt;
{% endif %}
</code></pre>
<p>Despite the fact that the value in that field with the current entry is &quot;2&quot;, I'm getting both buttons in template.</p>

<image><number>
Getting all images urls and help with numbers field
# Getting all images urls and help with numbers field

(Asked by: username_0 on 2021-07-26)

I have two problems with CraftCMS :(
First one - I want to make images gallery and now using something like this:
     {% set image = entry.car_photos[0] %}
{% if image %}
     
{% endif %}
        {% set image = entry.car_photos[1] %}
{% if image %}
     
{% endif %}
    {% set image = entry.car_photos[2] %}
{% if image %}
     
{% endif %}

The problem is that if the third image doesn't exist - I get the error. How can I make it work?
And second problem... I have field with my entries with number in it. So if the entry have that field with value "2" - I want to show text "On sale", if value "1" - I want to have "Out of stock". I tried with documentation but it doesn't help me... I tried something like this:
{% set soon = craft.entries()
    .Availability_Status('2')
    .all() %}
{% if soon %}
 Еще не объявлено
{% endif %}

{% set out = craft.entries()
    .Availability_Status('1')
    .all() %}
{% if out %}
 Еще не объявлено
{% endif %}

Despite the fact that the value in that field with the current entry is "2", I'm getting both buttons in template.

**Tags:** image, number

---

## 1 answers

### Answer by username_1 on 2021-07-27. Score: 1

It looks like you have 2 questions here?
1- why not run them through a loop? it will then only display the amount of images you have.
eg;
{% for images in entry.car_photos.all() %}

  

{% endfor %}

Second issue (probably should have had a second question for this).
You are pulling all of the entries out that have that status set and then displaying your if div if the query has succeeded. As long as there is any entry with that status that command will ALWAYS succeed.
In pseudocode what you are currently doing is this

Get all of the entries with a status of 2
if you got all of the entries with a status of 2 entries show this div

What you need to do is loop through your entries and display that div IF that status  matches.
Example:
{% for entries in craft.entries.all() %}
  
{% if entries.Availability_Status('1') %}
 Еще не объявлено
{% endif %}

{% endfor %}


---

