You are previewing SilverStripe 2.4 Module Extension, Themes, and Widgets.
O'Reilly logo
SilverStripe 2.4 Module Extension, Themes, and Widgets

Book Description

Create smashing SilverStripe applications by extending modules, creating themes, and adding widgets

  • The first and only book that focuses on extending SilverStripe sites

  • Step-by-step instructions covering everything you need to know for getting started with making the most of the core functionality, developing modules, creating themes, and adding widgets

  • Build a fun, real-world example application without breaking a sweat

  • Reviewed by Sigurd Magnusson, co-founder of SilverStripe, and Ingo Schommer, development manager at SilverStripe

  • In Detail

    HTML, CSS, JavaScript, PHP, databases, frameworks, CMS, and many other fast-evolving technologies make up modern web-development. How can you effectively create stunning results without being limited by the ease of your tools? That's where SilverStripe CMS comes into play.

    SilverStripe, with its simple and intuitive design, is easy to work with and offers numerous customization opportunities. But understanding the options available and getting hands-on with the development techniques is not a piece of cake and certainly not a delightful experience if you're relying on tutorials and documentation available online.

    Silverstripe 2.4 Module Extension, Themes, and Widgets: Beginner's Guide takes you through designing catchy and flexible templates, adding powerful features effortlessly, integrating everything into an intuitive backend for easy administration in a simple way, and implementing nifty features with minimal effort. From the most basic to complex forms, from simple to sophisticated pages, you'll learn how to get the most out of your SilverStripe application. SilverStripe keeps everything nice and simple, but if you need to, you can extend and customize every part of it. Graphic examples illustrate the general principle of operation, gradually introducing the finer details needed to get professional results. Common requirements such as image galleries, site search, and more can be reused or extended to fulfill your needs.

    The author's experience in designing and developing SilverStripe projects enables him to share insights on creating professional web applications in a clear and friendly way.

    You will start off with creating your own templates – covering the general layout, while also taking search engine optimization into consideration. Next, you will look at the logic driving your web application, and the database. Using these basic concepts, you will start building more advanced features. These include the integration of Google Maps, Twitter and Facebook, image galleries, the handling of user-supplied information, your own full-text search, and more. Finally, you'll even translate and internationalize your project. All of this can be easily achieved with SilverStripe.

    All of this and quite a bit more is covered by Silverstripe 2.4 Module Extension, Themes and Widgets: Beginner's Guide. Besides general principles, the focus is on reusable code – getting your project started in no time.

    A practical guide for extending SilverStripe applications with ease, describing real-life examples right from the start

    Table of Contents

    1. SilverStripe 2.4 Module Extension, Themes, and Widgets
      1. Table of Contents
      2. SilverStripe 2.4 Module Extension, Themes, and Widgets
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. Who this book is for
        3. Conventions
        4. Reader feedback
        5. Customer support
        6. Downloading the example code for this book
          1. Errata
          2. Piracy
          3. Questions
      8. 1. Principles and Concepts
        1. Why SilverStripe
          1. CMS and framework
          2. Openness and interoperability
          3. Getting your job done
        2. The file structure
          1. assets/
          2. cms/
          3. googlesitemaps/
          4. mysite/
          5. sapphire/
          6. themes/
        3. SilverStripe's ecosystem
          1. The company behind SilverStripe
          2. Documentation
            1. User help
            2. Developer documentation wiki
            3. API documentation
          3. Community
            1. Forum
            2. IRC chat
            3. Development mailing list
            4. Bug tracker
            5. Twitter
        4. Summary
      9. 2. Customizing the Layout
        1. Templates and themes
          1. Switching between themes
        2. Time for action—change the default theme
          1. What just happened?
          2. Getting more themes
        3. Template engine
          1. Another template engine?
        4. Taking a look at BlackCandy
          1. CSS
            1. editor.css
            2. layout.css, form.css, and typography.css
            3. ie6.css
          2. Templates
            1. Learning the very basics
            2. Starting to use templates
        5. Time for action—using site title and slogan
          1. What just happened?
          2. Layout
          3. Includes
          4. Have a go hero—using page name, navigation label, and metadata title
        6. Page control overview
          1. More placeholders
          2. Pop quiz—placeholders
          3. Casting placeholders
            1. Security
            2. Date formatting
          4. Have a go hero—add the time of the creation and when it was edited
          5. Users
          6. Control structures
            1. Handle with care
            2. Embedding and linking files
            3. Comments and base tag
            4. Conditional statements
            5. Control statements
          7. BlackCandy revisited
        7. Creating our own theme
        8. Time for action—files and folders for a new theme
          1. Basic layout
          2. File themes/bar/templates/Page.ss
        9. Time for action—the base page
          1. What just happened?
          2. File themes/bar/templates/Layout/Page.ss
        10. Time for action—the layout page
          1. What just happened?
          2. The includes: BasicInfo.ss, Menu.ss, and Footer.ss
        11. Time for action—the includes
          1. Have a go hero—create the layout and pages
          2. What's next?
        12. Not finding the #*?~^ error?
        13. Adding interactive features
        14. Time for action—let users share our page on Facebook and Twitter
          1. What just happened?
        15. Taking care of search engines
          1. Semantic HTML
          2. Meaningful URLs
          3. Broken links
          4. Duplicate content
          5. Meta tags
          6. Validation
          7. Sitemap
          8. Pop quiz—say hello to the current user
        16. Summary
      10. 3. Getting "Control" of Your System
        1. Model View Controller (MVC)
          1. Why the big fuss?
          2. View: Presenting your content
          3. Model: Managing your data
          4. Controller: Providing your logic
          5. Taking a look at an example
        2. Structure of a Page
          1. Page.php: Your initial start
          2. Convention over configuration revisited
          3. Extending classes is key
          4. Coding conventions
          5. Have a go hero—creating our own page
        3. Using the Controller
          1. Path constants
          2. The default page class
          3. Setting up CSS
            1. Including CSS files
        4. Time for action—adding a print style
          1. What just happened?
            1. Combining CSS files
        5. Time for action—reducing HTTP requests for CSS files
          1. What just happened?
            1. Adding custom CSS
          2. Pop quiz—duplication or not?
            1. Taking care of Internet Explorer
        6. Time for action—add your own head tags
          1. What just happened?
          2. Setting up JavaScript
            1. Including Google Analytics
        7. Time for action—adding custom JavaScript in the Controller
          1. What just happened?
            1. Blocking files
        8. Time for action—removing JavaScript in the Controller
          1. What just happened?
          2. Where to include CSS and JavaScript
        9. Coding conventions
          1. Coding
            1. Indentation
            2. Curly braces
            3. Check before looping
            4. Keeping the Controller clean
            5. Comments
          2. Methods
            1. Static methods
            2. Action handler methods
            3. Template methods
            4. Object methods
          3. Variables
          4. Element order
        10. Spam protecting e-mail addresses
          1. Controller
          2. Template
          3. CMS
        11. URL variables and parameters
          1. Activating changes
          2. Debugging
            1. Template
            2. Controller
            3. Request
            4. Debug
          3. Performance
          4. Debugging the code
        12. Adding an Intro page
          1. Time for action—add an Intro page
          2. What just happened?
          3. Pop quiz—basic principles
        13. Summary
      11. 4. Storing and Retrieving Information
        1. DBPlumber
          1. Your new best friend: DBPlumber
        2. Time for action—installing DBPlumber
          1. What just happened?
        3. From a database's point of view
        4. Adding custom fields to a page
        5. Time for action—putting content into the database
          1. What just happened?
        6. More data types and their form fields
          1. Have a go hero—transfer the other BasicInfo.ss elements to the CMS
        7. Global custom fields
          1. Configuration
          2. Code
            1. Database fields
            2. Accessing properties in the CMS
          3. Template
          4. Synchronize the database and you're ready to go
        8. How database values are fetched
          1. Pushing
          2. Pulling
        9. Taking the Model further
          1. Removing unused Page types
          2. Showing the Page type in the Page Tree
            1. Adding an image
            2. Don't change the file ending
            3. Using constants
          3. More SiteTree magic
          4. Cleaning up content fields
          5. Setting a meta title prefix
        10. Managing relations
        11. Time for action—linking pages together
          1. What just happened?
          2. Definition
          3. Adding relationships to the CMS
          4. Using it in the template
          5. Complex relationships
        12. Queries
          1. Security
            1. Casting
            2. Escaping
          2. Debugging queries
        13. Visible or invisible?
          1. In the Model
          2. In the Controller
        14. Summary
      12. 5. Customizing Your Installation
        1. Configuration in general
          1. Default settings
        2. Environment
          1. dev
          2. test
          3. live
          4. Defining a development server
          5. Server-wide configurations
        3. Logging
          1. Logging information
            1. Error levels
            2. SilverStripe and PHP errors
              1. Website errors
            3. Notification of errors
            4. Securing the logs
        4. Templates
        5. Security
        6. Customizing the CMS
          1. Removing tabs
          2. Rebranding the CMS
          3. Loading add-ons
        7. WYSIWYG
          1. Switching to HTML
          2. Removing buttons
          3. Adding buttons
          4. Configuring plugins
          5. Options
        8. Comments and spam
          1. Math questions
          2. Akismet
          3. Other measures
        9. E-mail
        10. Miscellaneous settings
          1. Accessing and advertising content
          2. Allowing file extensions
          3. Customizing Breadcrumbs
          4. Image quality
          5. JavaScript validators
          6. Defines
        11. Time for action—building our own configuration
        12. Managing your code
          1. Version control system
          2. VCS basics
          3. Using Git in your project
            1. Manual upgrade of core files
            2. Automatic upgrade of core files
            3. Contributing back
          4. Pop quiz—environment types
        13. Summary
      13. 6. Adding Some Spice with Widgets and Short Codes
        1. Widget or short code?
        2. Creating our own widget
        3. Time for action—embracing Facebook
          1. What just happened?
          2. Widgets in general
          3. Facebook graph API
          4. Connecting pages and widgets
            1. $SideBar
            2. What about the intro page?
          5. Facebook feed widget
            1. Facebook output
            2. The logic in general
          6. Taking a look at the details
            1. Error handling
            2. DBField::create
            3. DataObjectSet
          7. The template
          8. The other template
          9. More widgets
          10. Have a go hero—Twitter
        4. Text parser
        5. Time for action—doing it "right"
          1. What just happened?
        6. Caching
          1. Partial caching
          2. Static publisher
          3. Static exporter
          4. Restful service
        7. Partial caching
          1. Example
        8. Time for action—caching
          1. What just happened?
            1. Configuration
            2. Controller
            3. Template
            4. General considerations
          2. More on partial caching
          3. Carefully test your cache settings
          4. Cache directory
          5. Performance gains
            1. Server-side
            2. Client-side
        9. Creating our own short code
        10. Time for action—how to find us
          1. What just happened?
          2. What do we want to achieve?
          3. Configuration
          4. Model
            1. General composition
            2. Example-specific code
          5. Template
          6. Common pitfalls
          7. Go forth and build your own
          8. Pop quiz—too many options?
        11. Summary
      14. 7. Advancing Further with Inheritance and Modules
        1. Enhancing the intro page
        2. Time for action—adding the required modules
          1. What just happened?
        3. Time for action—extending the backend functionality
          1. What just happened?
          2. Introducing the DataObject class
            1. SiteTree
            2. DataObject
            3. DataObjectDecorator
          3. Making DataObjects sortable
          4. Adding our DataObject to the intro page
            1. Storing required information in the database
            2. Providing a field in the CMS
        4. Time for action—integrating our changes into the frontend
          1. What just happened?
          2. Working with images
          3. Image functions
            1. Images in the Controller
            2. Images in the View
          4. Pop quiz—SiteTree, DataObject, or DataObjectDecorator
        5. Image galleries
        6. Time for action—creating our own image gallery in the CMS
          1. What just happened?
          2. A single gallery image
          3. Image gallery container
        7. Time for action—our image gallery in the frontend
          1. What just happened?
          2. Image gallery template
        8. Transforming our code into a module
          1. Creating a module
          2. Required changes
        9. Time for action—adapting the module
          1. What just happened?
        10. Time for action—integrating the module into our page
          1. What just happened?
          2. Contribute back to the community
        11. Summary
      15. 8. Introducing Forms
        1. Building a contact form
        2. Time for action—creating a basic contact form
          1. The backend
          2. Including our form in the frontend
          3. Creating an e-mail template
          4. What just happened?
          5. The frontend
          6. The e-mail template
          7. The Model
          8. The Controller
            1. Setting up the form
            2. Processing the input
            3. Sending the e-mail
            4. Handling the success page
            5. Convention of method names
        3. Renting a table
          1. Going "abstract"
        4. Time for action—extending our form with abstraction
          1. The backend
            1. Changes in the template file
            2. Update the e-mail template
            3. What just happened?
            4. Abstract
              1. Model
              2. Controller
            5. Implementation
        5. Adding client-side validation
          1. Default client-side validation
          2. Enhanced client-side validation
        6. Time for action—using jQuery's Validation plugin on the contact page
          1. What just happened?
            1. jQuery's Validation plugin
        7. Time for action—using jQuery's Validation plugin on the rent page
          1. What just happened?
            1. Setting up the Datepicker
          2. Should you add JavaScript to the Controller?
        8. Tougher server-side validation
        9. Time for action—better server-side validation
          1. What just happened?
          2. Have a go hero—order a member card
          3. Pop quiz—true or false
        10. Summary
      16. 9. Taking Forms a Step Further
        1. Searching our pages
        2. Time for action—adding search functionality to our page
          1. What just happened?
          2. The Controller part of the code
          3. The View part of the code
        3. Customizing forms even further
          1. Overwriting the global template
          2. Handcrafting forms with SilverStripe
        4. Saving data to the database
        5. Time for action—extending the member card form
          1. What just happened?
          2. The Model part of the code
          3. Setting up the fields
            1. New arguments for TextField
            2. OptionsetField
            3. CheckboxField
            4. DateField options
          4. Checking for invalid data and duplicate e-mail addresses
          5. Saving a new entry to the database
        6. Field types overview
          1. ConfirmedPasswordField
          2. HiddenField
          3. More
        7. Checking the e-mail address for uniqueness
        8. Time for action—checking the e-mail's uniqueness with Ajax
          1. What just happened?
        9. Doing more with sessions
        10. Time for action—using the session in forms
          1. What just happened?
        11. How to store members in the database
          1. Pop quiz—advanced forms
        12. Summary
      17. 10. Targeting the Whole World
        1. Globalization in general
        2. Globalization in the CMS
        3. Time for action—configuring the CMS for globalization
          1. What just happened?
        4. Globalization in the code
          1. Have a go hero
          2. Localizing and internationalizing the templates
            1. Starting our globalization efforts
        5. Time for action—globalizing the intro page
          1. What just happened?
            1. Generating locale files
          2. Localizing and internationalizing the PHP code
        6. Time for action—translating the rent form
          1. What just happened?
          2. Localizing and internationalizing JavaScript
        7. Time for action—translating the rent form's JavaScript
          1. What just happened?
          2. Have a go hero
        8. Getting the right content
        9. Time for action—switching the locale
          1. What just happened?
          2. Pop quiz—if or when should you globalize
        10. Where to go from here
          1. More modules
          2. Adding more ideas and features to your page
        11. Summary
      18. A. Pop Quiz Answers
        1. Chapter 2, Customizing the Layout
          1. Pop quiz—placeholders
          2. Pop quiz—say hello to the current user
        2. Chapter 3, Getting "Control" of Your System
          1. Pop quiz—duplication or not?
          2. Pop quiz—basic principles
        3. Chapter 5, Customizing Your Installation
          1. Pop quiz—environment types
        4. Chapter 6, Adding Some Spice with Widgets and Short Codes
          1. Pop quiz—too many options?
        5. Chapter 7, Advancing Further with Inheritance and Modules
          1. Pop quiz—SiteTree, DataObject, or DataObjectDecorator
        6. Chapter 8, Introducing Forms
          1. Pop quiz—true or false
        7. Chapter 9, Taking Forms a Step Further
          1. Pop quiz—advanced forms
        8. Chapter 10, Targeting the Whole World
          1. Pop quiz—if / when should you globalize
      19. Index