Jump to:

3448 Posts in 1032 Topics by 873 members

Template Questions

SilverStripe Forums » Template Questions » Escape period after php variable inside html attribute.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2357 Views
  • theoldlr
    Avatar
    Community Member
    103 Posts

    Escape period after php variable inside html attribute. Link to this post

    In side of a <% control %> I am displaying the languages my site is available in. I wanted to use the flags to represent the languages. I am doing this like so:

    <img src="/imagepath/$image.png" />

    The '.' interferes with the php variable and the browser sees the code as <img src="/imagepath/" />

    the variable $image in this case returns the locales for the languages (i.e. en_US, pt_BR, etc.) so I cannot append .png to the value of variable as this variable is used for other things as well. How do I escape the '.' properly? I have tried $image\.png which ends up returning 'en_US\.png'

    thanks in advance!

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Escape period after php variable inside html attribute. Link to this post

    Wrap it in curly braces:

    <img src="/imagepath/{$image}.png" />

    2357 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.