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?
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
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?
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
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 :)
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.