Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

Header image based on URLSegment


Go to End


2 Posts   1636 Views

Avatar
dubtje

Community Member, 17 Posts

6 August 2011 at 7:15am

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.

Avatar
dubtje

Community Member, 17 Posts

6 August 2011 at 7:29am

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