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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

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

Trying to create custome image SRC field from $Title


Go to End


4 Posts   2053 Views

Avatar
lubzee

Community Member, 15 Posts

2 October 2008 at 9:50pm

I want to reference images based on page titles as in:

<img src="$Title.jpg" />

How can I escape the $Title part so that it would render the page title and extension as one string. As in Home.jpg

Is this possible?

Avatar
Willr

Forum Moderator, 5523 Posts

2 October 2008 at 9:54pm

You need to add { } around the variable to tell SS what it is. Eg at the moment it will be looking for a field $Title.jpg which is wrong. You need to do {$Title}.jpg

Avatar
lubzee

Community Member, 15 Posts

2 October 2008 at 10:02pm

Thanks for the quick reply...

Would this be the 'correct' way to do something like this.. I can't maybe create a custom property from the controller side that would add the extension and output the final string and just call it as something like $TitleImage?

I'm still fairly new to this great CMS and mvc concepts :)

Avatar
Willr

Forum Moderator, 5523 Posts

2 October 2008 at 10:14pm

You could do but that would be over designing it. Tho the 1 thing I would say is you can have spaces in titles, a safer option would be to use $URLSegment which would return things like 'home', 'about-us', 'blog' etc and $URLSegment doesn't has spaces - Images URLs would fail with spaces.