Jump to:

3435 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » Header image based on URLSegment

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

Page: 1
Go to End
Author Topic: 713 Views
  • dubtje
    Avatar
    Community Member
    17 Posts

    Header image based on URLSegment Link to this post

    Hello,

    I want to use a different header-image based on the url-segment of the page.
    I've found some forumposts about this theme, but there it's up to the user to choose a headerimage in the backend. It's my aim to automate this.

    So I've put this in my Page.ss

    <div id="header">
       <img src="$ThemeDir/images/PageLeerling/titelafbeeldingen_leerlingen/$URLSegment.png" alt="" name="achtergrond_header" id="achtergrond_header" />
    </div>

    I've prepared the different headerfiles according to the url segments.

    But when I look in the sourcecode of the rendered page, I see this:
    <div id="header">
       <img src="themes/guatemala/images/PageLeerling/titelafbeeldingen_leerlingen/" alt="" name="achtergrond_header" id="achtergrond_header" />
    </div>

    so apparantly $URLSegment isn't picked up.

    Is it possible to achieve this whitout coding in the controller? Or, if so, what do I have to do?

    Thanks.

  • dubtje
    Avatar
    Community Member
    17 Posts

    Re: Header image based on URLSegment Link to this post

    As so often, I found the answer just after posting the question.
    I had to 'escape' the placeholder with {}, so {$URLSegment} did the trick

    713 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.