What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hey guys πŸ™‚ We have an application with 2 stores (DE, UK). In a molecule I cre

U010MP7GCTV
U010MP7GCTV Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

Hey guys πŸ™‚

We have an application with 2 stores (DE, UK). In a molecule I created I want to load a different twig template depending on the active store. How can I do that?
If not possible how could I use the same twig template but show different content depending on the active store? (would be a bad solution because there will be more stores in the future)

Thanks for helping πŸ™‚

Β«1

Comments

  • have you tried the β€˜codebucket’ approach?

  • where you can put the template in a store-specific module extension?

  • Unknown
    edited July 2020

    like FoobarDE/…/template.twig

  • not 100% sure this is correct, but worth a quick try

  • U010MP7GCTV
    U010MP7GCTV Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    I have this path:
    src\Pyz\Yves\ShopUi\Theme*default*\components\molecules\my-module\my-module.twig

    I tried to create these 2 versions:
    src\Pyz\Yves\ShopUi\Theme*DE\components\molecules\my-module\my-module.twig
    src\Pyz\Yves\ShopUi\Theme*UK
    \components\molecules\my-module\my-module.twig

    But they are not used, the application always uses the default one

  • nope, try more like src\Pyz\Yves\ShopUiDE\Theme\components\molecules\my-module\my-module.twig

  • but that is also not only working for templates

  • i can give you a bit better approach after my meeting

  • U010MP7GCTV
    U010MP7GCTV Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    That would be great, I am waiting for you. Thank you a lot πŸ™‚

  • Helen Laktionova
    Helen Laktionova Sprykee Posts: 33 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited July 2020

    If we need to have just different templates: use Marko`s approach
    But if you want to have a different content: depends on the content.

    F.e. if it is some dynamic content (like prices etc) - it is ok.

    If content totally different - could be better to use different approach in general

  • Helen Laktionova
    Helen Laktionova Sprykee Posts: 33 πŸ§‘πŸ»β€πŸš€ - Cadet

    Like different CMS blocks structure and relate blocks to proper stores

  • maybe you can already elaborate on your scenario in the meantime, @U010MP7GCTV

  • U010MP7GCTV
    U010MP7GCTV Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    I tried this structure
    src\Pyz\Yves\ShopUiDE\Theme\components\molecules\my-module\my-module.twig
    src\Pyz\Yves\ShopUiUK\Theme\components\molecules\my-module\my-module.twig

    ... and also this ...
    src\Pyz\Yves\ShopUiDE\Theme\default\components\molecules\my-module\my-module.twig
    src\Pyz\Yves\ShopUiUK\Theme\components\default\molecules\my-module\my-module.twig

    .. cleared the cache and did a frontend build but it's still taking the default one πŸ˜•

  • and it is just about the template, right?

  • U010MP7GCTV
    U010MP7GCTV Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    Yep right πŸ™‚

  • k, got it. gimme a minute

  • U010MP7GCTV
    U010MP7GCTV Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    Okay thank you

  • so, what you have to do is put the template to

  • src/Pyz/Yves/ShopUi/Theme/DE/components/molecules/footer-logo/footer-logo.twig , assuming this should only be valid for DE

  • whereas DE in this path actually refers to an alternative theme and does not necessarily have to be identical to the store

  • and then!

  • you have to extend the according twig config in shared to use that theme

  • <?php
    
    namespace Pyz\Shared\TwigDE;
    
    use Spryker\Shared\Twig\TwigConfig as SprykerTwigConfig;
    
    class TwigConfig extends SprykerTwigConfig
    {
        /**
         * @return string
         */
        public function getYvesThemeName(): string
        {
            return 'DE';
        }
    }
    
  • hope that helps

  • for the assets there was another step involved πŸ€”

  • U010MP7GCTV
    U010MP7GCTV Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet

    Hey Marco, the theme seperation worked, I get the DE molecule in the DE shop now.

    Unfortunately the asset Urls are wrong. The app tries to load:
    /assets/DE/DE/css/yves_default.app.css

    instead of
    /assets/DE/default/css/yves_default.app.css

    I already created the frontend build config as it is described in the link you posted

  • doesn’t work? πŸ€”

  • U010MP7GCTV
    U010MP7GCTV Posts: 28 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited July 2020

    It compiles the DE assets to ".../DE/default/"

    but tries to load them in the browser from ".../DE/DE/"

  • works perfeclty fine for me πŸ€”