Search code examples
assetssylius

How to handle assets in a Sylius theme?


I'm new to Sylius and I have many issues handling shop customization. My current issue is adding assets (images, css...) to my custom theme. I've tried every way but I can't figure it out. My questions are:

  1. Where are you supposed to put them exactly?
  2. How do you get them to the public folder? I tried the assets:install and sylius:theme:assets:install commands, but since I don't know where to put the files in the first place it didn't really help.
  3. How do you reference them in your templates? I can't find where the asset() function points to.

Context

  • I'm using the most recent versions of Sylius Standard (1.7.0), Windows 10 Pro and Firefox
  • The theme works, I can select it in the channel settings and I can overwrite the templates and the translations no problem in my themes/SomethingTheme/SyliusShopBundle folder

I've seen similar issues on Stack Overflow but they don't seem relevant to this version of Sylius.


Solution

  • I've placed the public folder of my assets inside the SyliusShopBundle of the theme. These files are copied to the public folder after the command

    sylius:theme:assets:install
    

    is executed.

    Here is a image to my folder structure

    Here a implementation inside the theme

    <div class="column">
    <a href="{{ path('sylius_shop_homepage') }}"><img src="{{ asset('bundles/syliusshop/assets/logo_fitfoods.svg') }}" alt="Sylius logo" class="ui small image" /></a>