1

Just starting to play with Craft going to be a learning curve coming from wp and processwire etc.

I created a custom Global Set and called it Logo which I assumed I could use in the _layout.html template to show a logo in the header and make it easy to change etc.

I called the set Logo and it has a handle of logo. This created the Globals option in the top nav. Here I was able to upload a logo from my assets etc.

Now in the _layout.html template I am trying to access this image by using the following but nothing shows up.

<img src="{{ Logo.logo }}">

Based on the docs it says: You can access your Global Sets from any template via their handles. For example, if you have a Global Set with the handle “companyInfo”, and it has a field with the handle “yearEstablished”, you can access that field anywhere using this code:

{{ companyInfo.yearEstablished }}

I also tried

<img src="{{ Logo.logo.url() }}">

What am I doing wrong am I going about this the wrong way?

3

Image fields are an array, because you can have multiple images within that field. Usually you would loop through the array to output your images:

{% if Logo.logo | length %}
    {% for image in Logo.logo %}
        {{ image.url }}
    {% endfor %}
{% endif %}

Or, if you only have a single image in the array, you can just do this:

{% set image = Logo.logo.first() %}

{% if image %}
    {{ image.url }}
{% endif %}

More info on Asset templating here

  • Thanks but I already tried that as well and it wasn't working. It's always empty so it doesn't get past the if statement. – Bowenac Apr 24 '15 at 2:26
  • 1
    Make sure you are using the globalSet handle and not the title. I would guess that it is all lowercase. {{ logo.logo.first.url }} – Douglas McDonald Apr 24 '15 at 5:21
  • Thank you that was it, Looking back I read the docs wrong and thought I was supposed to use the Global Set Name.Handle but now I know its globalSetHandle.FieldName thanks for help much appreciated. Really liking craft so far. – Bowenac Apr 24 '15 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.