2

I haven't used Craft in a while now and I have just revisited it, I'm trying to output an image URL from a global matrix field like so:

{% for block in globalName.matrixField %}

    {% if block.type == "blockType1" %}

        {% set image = block.blockType1.first() %}

        <a href="{{ image.getUrl() }}">link</a>

    {% endif %}

{% endfor %}

But it keeps outputting as: {{ siteUrl }}/resources/images/my-image.jpg (instead of actually outputting the website URL).

Am I missing something?

2 Answers 2

3

If your putting the variable in the craft settings input, try wrapping it in single brackets like {siteUrl} instead of {{ siteUrl }}

That should do the trick

1
  • Sorry, forgot to come back here when I fixed it, yeah this was partially the problem, I was trying to do this through my asset sources too (then realised I could just reference them relative). Thanks!
    – Lighty_46
    Nov 18, 2014 at 14:38
1

I'm guessing you're defining your siteUrl as an environment variable?

Try setting it as the actual siteUrl config setting, rather than a siteUrl environment variable.

See here for an explanation.

2
  • Yeah I did have it set up as an environment variable (And I am able to output the website url using {{ siteUrl }} so that's working fine) ... but I added in the config setting too and that hasn't made a difference. The link still appears as <a href="{{ siteUrl }}/resources/images/image.jpg">link</a>
    – Lighty_46
    Nov 14, 2014 at 0:09
  • When you added the config setting, did you remove the environment variable?
    – Brad Bell
    Nov 14, 2014 at 0:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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