$30 off During Our Annual Pro Sale. View Details »

One Code To Run Them All

One Code To Run Them All

Lightning talk at StripeCon EU 2019. How I managed to use one repository for two slightly different Silverstripe CMS installations.

wernerkrauss

October 12, 2019
Tweet

More Decks by wernerkrauss

Other Decks in Programming

Transcript

  1. One Code To Run Them All
    12.10.2019 www.silverstrip.es 1

    View Slide

  2. The use case: Primo Products
    • Two online shops for New Zealand and
    Australia
    – https://primopromo.com.au/
    – https://www.primoproducts.co.nz/
    • 99% same code
    • One installation needs other extensions
    • Some different configurations (currency)
    • Same design, some minor differences (address
    in footer…)
    12.10.2019 www.silverstrip.es 2

    View Slide

  3. With SilverStripe 3
    • Two repositories with each settings
    • One theme per installtion
    • Double work updating, testing
    12.10.2019 www.silverstrip.es 3

    View Slide

  4. With Silverstripe CMS 4
    • More flexibility
    • One code base for both installations
    • Switch between shops via ENVIRONMENT
    variable
    • Sub-themes for shop specific tweaks
    12.10.2019 www.silverstrip.es 4

    View Slide

  5. ENVIRONMENT
    • A server specific setting
    • A switch for configuration
    12.10.2019 www.silverstrip.es 5

    View Slide

  6. 12.10.2019 www.silverstrip.es 6

    View Slide

  7. 12.10.2019 www.silverstrip.es 7

    View Slide

  8. 12.10.2019 www.silverstrip.es 8

    View Slide

  9. Sub-Themes
    • SilverStripe cascades through a set of themes
    • The first valid file is returned
    • Only modify the files you need to change
    • Works for all files via URLResourceLoader
    • Templates, images, CSS, JS …
    12.10.2019 www.silverstrip.es 9

    View Slide

  10. 12.10.2019 www.silverstrip.es 10

    View Slide

  11. 12.10.2019 www.silverstrip.es 11

    View Slide

  12. Different PHP Code
    • Some Extensions are only applied for a specific
    shop
    • Some methods check the ENVIRONMENT
    12.10.2019 www.silverstrip.es 12

    View Slide

  13. Conclusion
    • Combine different tools
    • Simplify your project
    • Satisfy your customer
    12.10.2019 www.silverstrip.es 13

    View Slide

  14. Thanks!
    www.silverstrip.es
    12.10.2019 www.silverstrip.es 14

    View Slide