<p>I'm a beginner myself but have used assets plenty of times. It should be something like this:</p>

<pre><code>{% set entry = craft.entries.section('gallery').first() %}
{% set assets = entry.gallery %}
{% if assets | length %}
    {% for asset in assets %}
        &lt;img src="{{ asset.getUrl('imgTransform') }}" width="{{ asset.getWidth('imgTransform') }}" height="{{ asset.getHeight('imgTransform') }}" alt="{{ entry.title }}"&gt;
    {% endfor %}
{% endif %}
</code></pre>

<p>I use a set entry instead of a for loop because I'm assuming you only have one entry (one gallery). Maybe use a single section instead of a channel than? If you have multiple galleries, a channel is perfect, than you can use a for loop.</p>

<p>The imgTransform can be set in your assets page in the Control Panel. More info: <a href="http://buildwithcraft.com/docs/image-transforms" rel="nofollow">http://buildwithcraft.com/docs/image-transforms</a></p>

CC BY-SA 3.0
2014-11-16T11:57:54.087Z
So where do you put this code? In a new template? I am really new to this. A one-gallery solution is perfectly fine. Could you please give me detailed instruction for that? thanks
Csaba Dobo
CC BY-SA 3.0
2014-11-16T12:04:26.970Z
Yes. Just a HTML file that you reference to in your channel settings. For example gallery.html. You can put the name of your template into the bottom input field of your channel settings in the CP. Than when you go to yoursite.com/gallery it'll load the template and output your gallery. Take a look at https://github.com/pixelandtonic/HappyLager/tree/master/final/web for some examples.
Tom De Smet
CC BY-SA 3.0
2014-11-16T13:33:42.097Z
@TomDeSmet You had an extra endfor at the end that I removed. I hope you don't mind the edit. ;)
Douglas McDonald
CC BY-SA 3.0
2014-11-16T13:34:56.130Z
Certainly not :) Will double check my code next time. Thanks!
Tom De Smet
CC BY-SA 3.0
2014-11-16T11:31:36.727Z
2014-11-16T13:29:53.583Z
2014-11-16T13:29:53.583Z
Tom De Smet
<p>I thought I might fill in a few extra details to support <a href="https://craftcms.stackexchange.com/a/4746/784">Tom De Smet's excellent answer</a>.</p>

<p>If you only need one gallery then as Tom suggested you can change the section type from a <code>channel</code> to a <code>single</code> in the section's settings. Where you choose to display the gallery is completely up to you. It can either be displayed in it's own template (the one you define in the section's settings), or just as easily in any other template or page on your site.</p>

<p>If displayed in its own template, and if using a <code>single</code> then the template might be something like <code>gallery.html</code> or <code>gallery/index.html</code>, either of which could be accessed by the url <code>mysite.com/gallery</code>. If using a channel (with one or more gallery entries) then a common convention would be to use <code>gallery/_entry.html</code>, which could be accessed using the url <code>mysite.com/gallery/my-gallery-slug</code>.</p>

<p>Whenever a request is made to either of these uri patterns craft will automatically provide an <code>entry</code> variable to the template populated with an <code>EntryModel</code> for the gallery entry — in which case you do not need to retrieve the entry using <code>{% set entry = craft.entries.section('gallery').first() %}</code> as <code>entry</code> will already be pre-defined.</p>

<p>If on the other hand you want to display the gallery somewhere else on your site (in some other template) then you will first need to retrieve the gallery entry using <code>{% set entry = craft.entries.section('gallery').first() %}</code> or <code>{% set entry = craft.entries.section('gallery').slug('my-gallery-slug') %}</code>.</p>

<p>Also, keep in mind that using a <code>structure</code> with multiple <code>EntryTypes</code> defined (one of which could be 'gallery') would be another way to essentially house various 'singles' together with the advantage that you can then generate heirarchical site navigation from the structure.</p>

CC BY-SA 3.0
2014-11-16T19:06:02.533Z
Hello, many thanks for your answers. Let me ask this too: is the above code for single age type or for channels or for both?
Csaba Dobo
CC BY-SA 3.0
2014-11-16T19:19:58.710Z
Most of the code on both answers will work for singles, channels, or structures. The difference is that in a channel or structure (where there can be more than one) you need to either loop through the entries or provide some additional identifier (i.e. id(), slug(), first(), etc.) to retrieve the one you are looking for. And if you're using the defined template path then `entry` will already be defined and you can just access it directly (i.e. `{{ entry.title }}` ).
Douglas McDonald
CC BY-SA 3.0
2014-11-16T19:59:44.647Z
I feel sorry for my beginner questions. I converted this setup to a single, inserted the code above to a gallery.html file but get this: "Internal Server Error

Craft\EntryModel and its behaviours do not have a method or closure named "gallery"." In under Entries/singles/gallery I only have Title input field. Maybe that is why it is not working. I would post a screenshot but can not do that here.
Csaba Dobo
CC BY-SA 3.0
2014-11-16T20:30:37.057Z
Ah yes. You need to add your field 'gallery' to the fieldLayout of your single, also called gallery. You can do this in settings>sections>gallery>entry type>gallery, then drag the field to your sections field layout.
Douglas McDonald
CC BY-SA 3.0
2014-11-16T20:53:45.787Z
It is getting better. Now I managed to add the assets to the single net to title. But now what I get is: "Internal Server Error
The transform “imgTransform” cannot be found!" I had previously set up image transfer in the control panel, but no effect so I deleted it. Do I have to write something in the code in the gallery.html template? hm??
Csaba Dobo
CC BY-SA 3.0
2014-11-16T21:05:48.627Z
Never mind. My image transform had a different name. Thanks for al the help. I think I will have more. Maybe one for now: are there any case studies or step-by-step guides available? Perhaps with screenshots? How do you get started quickly?
Csaba Dobo
CC BY-SA 3.0
2014-11-17T00:14:03.790Z
@CsabaDobo Check out https://mijingo.com/products/screencasts/craft-cms-tutorial/
Brad Bell
CC BY-SA 3.0
2014-11-16T15:07:56.497Z
2014-11-16T16:49:32.767Z
2017-04-13T12:51:00.303Z
Douglas McDonald
<p>Just installed the cms last night. I am looking for a step-by-step instruction on how to create a gallery and display it.</p>

<p>So far I have created the:
- channel called: Gallery
- section called: Gallery
- entry type: Gallery
- the assets field named: gallery
- added 4 images
- created a new entry called: Gallery (only the Title is visible so far) and this is where I got stuck. </p>

<p>Any help would be greatly appreciated</p>

<gallery>
How to build a simple gallery
# How to build a simple gallery

(Asked by: username_0 on 2014-11-16)

Just installed the cms last night. I am looking for a step-by-step instruction on how to create a gallery and display it.

So far I have created the:
- channel called: Gallery
- section called: Gallery
- entry type: Gallery
- the assets field named: gallery
- added 4 images
- created a new entry called: Gallery (only the Title is visible so far) and this is where I got stuck.

Any help would be greatly appreciated

**Tags:** gallery

---

## 2 answers

### Answer by username_1 on 2014-11-16. Score: 3

I'm a beginner myself but have used assets plenty of times. It should be something like this:
{% set entry = craft.entries.section('gallery').first() %}
{% set assets = entry.gallery %}
{% if assets | length %}
    {% for asset in assets %}
        
    {% endfor %}
{% endif %}

I use a set entry instead of a for loop because I'm assuming you only have one entry (one gallery). Maybe use a single section instead of a channel than? If you have multiple galleries, a channel is perfect, than you can use a for loop.
The imgTransform can be set in your assets page in the Control Panel. More info: http://buildwithcraft.com/docs/image-transforms

> **Comments:**
> **username_0**: So where do you put this code? In a new template? I am really new to this. A one-gallery solution is perfectly fine. Could you please give me detailed instruction for that? thanks  
> **username_1**: Yes. Just a HTML file that you reference to in your channel settings. For example gallery.html. You can put the name of your template into the bottom input field of your channel settings in the CP. Than when you go to yoursite.com/gallery it'll load the template and output your gallery. Take a look at https://github.com/pixelandtonic/HappyLager/tree/master/final/web for some examples.  
> **username_2**: @TomDeSmet You had an extra endfor at the end that I removed. I hope you don't mind the edit. ;)  
> **username_1**: Certainly not :) Will double check my code next time. Thanks!  

---

### Answer by username_2 on 2014-11-16. Score: 1

I thought I might fill in a few extra details to support [Tom De Smet's excellent answer](https://craftcms.stackexchange.com/a/4746/784).

If you only need one gallery then as Tom suggested you can change the section type from a `channel` to a `single` in the section's settings. Where you choose to display the gallery is completely up to you. It can either be displayed in it's own template (the one you define in the section's settings), or just as easily in any other template or page on your site.

If displayed in its own template, and if using a `single` then the template might be something like `gallery.html` or `gallery/index.html`, either of which could be accessed by the url `mysite.com/gallery`. If using a channel (with one or more gallery entries) then a common convention would be to use `gallery/_entry.html`, which could be accessed using the url `mysite.com/gallery/my-gallery-slug`.

Whenever a request is made to either of these uri patterns craft will automatically provide an `entry` variable to the template populated with an `EntryModel` for the gallery entry — in which case you do not need to retrieve the entry using `{% set entry = craft.entries.section('gallery').first() %}` as `entry` will already be pre-defined.

If on the other hand you want to display the gallery somewhere else on your site (in some other template) then you will first need to retrieve the gallery entry using `{% set entry = craft.entries.section('gallery').first() %}` or `{% set entry = craft.entries.section('gallery').slug('my-gallery-slug') %}`.

Also, keep in mind that using a `structure` with multiple `EntryTypes` defined (one of which could be 'gallery') would be another way to essentially house various 'singles' together with the advantage that you can then generate heirarchical site navigation from the structure.

> **Comments:**
> **username_0**: Hello, many thanks for your answers. Let me ask this too: is the above code for single age type or for channels or for both?  
> **username_2**: Most of the code on both answers will work for singles, channels, or structures. The difference is that in a channel or structure (where there can be more than one) you need to either loop through the entries or provide some additional identifier (i.e. id(), slug(), first(), etc.) to retrieve the one you are looking for. And if you're using the defined template path then `entry` will already be defined and you can just access it directly (i.e. `{{ entry.title }}` ).  
> **username_0**: I feel sorry for my beginner questions. I converted this setup to a single, inserted the code above to a gallery.html file but get this: "Internal Server Error  Craft\EntryModel and its behaviours do not have a method or closure named "gallery"." In under Entries/singles/gallery I only have Title input field. Maybe that is why it is not working. I would post a screenshot but can not do that here.  
> **username_2**: Ah yes. You need to add your field 'gallery' to the fieldLayout of your single, also called gallery. You can do this in settings>sections>gallery>entry type>gallery, then drag the field to your sections field layout.  
> **username_0**: It is getting better. Now I managed to add the assets to the single net to title. But now what I get is: "Internal Server Error The transform “imgTransform” cannot be found!" I had previously set up image transfer in the control panel, but no effect so I deleted it. Do I have to write something in the code in the gallery.html template? hm??  
> **username_0**: Never mind. My image transform had a different name. Thanks for al the help. I think I will have more. Maybe one for now: are there any case studies or step-by-step guides available? Perhaps with screenshots? How do you get started quickly?  
> **username_3**: @CsabaDobo Check out https://mijingo.com/products/screencasts/craft-cms-tutorial/  

---

