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.

Archive /

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

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

Trying to create custome image SRC field from $Title


Reply


4 Posts   1624 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, 5513 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, 5513 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.