I’m in the process of upgrading a website from SilverStripe 3 to version 4.1.0. Currently I specify SiteTree icons for custom page types as follows:
class ProductPage extends Page
{
private static $icon = "mysite/icons/product.png";
Now, the icon seems to only correctly appear in the SiteTree if I keep a copy in two locations! These are:
/mysite/icons
/public/resources/mysite/icons
Missing one of them will cause either the generic Page icon to be displayed, or it is left blank.
Have I got something completely wrong here? I’d assume I’d only need to keep a copy of the icon in one place? Any help you can give would be much appreciated.
If you’re making use of the public folder in SS4.1+ (which is a good idea) then static resources like images need to be served up from that directory. If you want to store them in your mysite/icons directory that’s fine, but you need to expose that directory so it gets symlinked to the resources directory.
Try deleting the /public/resources/mysite/icons directory, then add the following config to your composer.json file, then run the terminal command composer vendor-expose in your project root, which will take care of the symlinking.
"extra": {
"expose": [
"mysite/icons"
]
}
Alternatively (and more simply), you should be able to store your icons at public/icons instead of mysite/icons and reference them relative to the public folder e.g. $icon = "icons/product.png".