Twill CMS Documentation

repository·3.x·Indexed 26 days ago

https://github.com/area17/twill

An open-source CMS framework built for Laravel that enables developers to create custom admin consoles using pre-built Vue.js components. Twill provides a flexible, modular architecture that supports both standard Laravel applications and headless CMS implementations, offering granular user management with role, roleGroup, and roleGroupItem permission levels.

Tokens
91.9K
Snippets
295
Records
490
Agent score
87%

What's inside Twill

  1. Overview of Twill CMS

    3.x

    Twill is an open source Laravel package designed for rapidly creating custom, flexible content management systems (CMS). It provides a feature-rich admin console with pre-built Vue.js UI components while maintaining full developer control.

    Key characteristics include:

    • No lock-in: You can create new data models or hook into existing ones.
    • Flexible architecture: Can be used within a standard Laravel application or as a headless CMS.
    • Modular: You can disable features you do not need to avoid bloat.
    • Developer-centric: No need to write or adapt HTML for the admin UI, and it is fully extensible.
  2. Understand Twill Module structure

    3.x

    In Twill, a Module represents a single content type. A module consists of several key files that work together to bridge your data with the CMS UI:

    • Model Class (app/Models): A standard Laravel Eloquent model defining the content type and database connection.
    • Module Controller Class (app/Http/Controllers/Twill): Acts as a bridge between your model and the Twill CMS front-end UI.
    • Repository Class (app/Repositories): Handles saving, reading, and custom pre/post-save logic for your model.
    • Requests Class (app/Http/Requests/Twill): Used for form validation.
    • Form Blade File (Optional): Defines how the form appears in the CMS.
  3. Core Features of Twill

    3.x

    Twill provides several modules and UI components to accelerate CMS development:

    Modules

    • Enhanced Laravel Resources: Uses standard Laravel concepts like migrations, models, controllers, form requests, repositories, and Blade views.
    • CLI Generator: Command line tools and conventions to speed up the creation of new content types.
    • Custom Forms: Fully customizable forms per content type.
    • Slug Management: Includes automatic redirection for old URLs.
    • Content Listings: Configurable listings with searching, filtering, sorting, publishing, featuring, and reordering.
    • Relationship Support: Supports all Eloquent ORM relationships (1-1, 1-n, n-n, polymorphic).
    • Versioning: Built-in content versioning.

    CMS UI Components

    • Vue.js Form Components: A large library of abstracted components (Input, Text Area, Rich Text Area, Select, Multi-select, Date/Color pickers).
    • WYSIWYG: Configurable editor built with TipTap.
    • Content Block Editor: A flexible, dynamically composable editor using all available form components.
    • Form Repeaters: For handling collections of data within a form.
    • Translation Support: Inline translated fields with independent publication status.

    Media Library

    • File Management: Supports S3 and imgix (swappable with other 3rd party services).
    • Image Handling: Smart cropping, multiple crops for responsive art direction, and custom requirements per content type.
    • Organization: Batch uploading, tagging, and metadata editing (alt text, caption).
    • Search: Multi-field search (filename, alt text, tags, dimensions, etc.).
  4. Understand default User Management roles and permissions

    3.x

    Twill leverages Laravel's authentication and authorization. By default, users can log in at /login and reset passwords via the same screen. New users must reset their password before accessing the admin application.

    Default Roles

    • view only: Can login, view/filter CRUD listings, view/download media/files, and edit their own profile.
    • publisher: All 'view only' permissions plus full CRUD, publish, sort, feature, and uploading new media/files.
    • admin: All 'publisher' permissions plus full permissions on users.
    • super admin: Can impersonate any user at /users/impersonate/{id}. To stop impersonating, visit /users/impersonate/stop.
  5. Understand Twill Packages

    3.x
    Packages in Twill are used to add or create reusable functionality. A Twill package is fundamentally a standard Laravel package, but it must extend or utilize the TwillPackageServiceProvider to integrate correctly with the Twill ecosystem. Packages are self-registering and can contain Capsules. They are managed and installed via Composer.
  6. Configuration-based Features in Twill

    3.x

    Twill allows you to configure several high-level CMS features via configuration files:

    • User Management: Authentication, authorization, and user management.
    • Navigation: A three-level hierarchy with breadcrumbs for content structure.
    • Dashboard: Configurable dashboard with quick access links, activity logs, and Google Analytics integration.
    • Global Search: Configurable search across the CMS.
    • Content Featuring: A 'bucket' UI to manage featured content or localization settings.
  7. Understand the concept of Twill Modules

    3.x

    In Twill, a module is the fundamental unit of functionality. It consists of a set of files that define a specific content model and its associated business logic within your application. Modules allow you to configure features for content publishers, such as:

    • Translations: Enabling multi-language support for content.
    • Media Attachments: Allowing users to attach images and other media to records.
    • Complex Data Structures: Defining sophisticated relationships and data types within your content records.
  8. Understand Twill Modules

    3.x

    A Twill module is a set of classes and configurations in your Laravel application that enables publishers to manage specific content types. Modules function as feature-rich Laravel resources (CRUD modules) providing operations like Create, Read, Update, Delete, Publish, Feature, Tag, Preview, Restore, Reorder, and Bulk edit.

    Modules are implemented using PHP traits in your Eloquent models and Twill repositories, following Laravel's migration and Eloquent conventions. They typically consist of a listing page and a form page or modal.

  9. Overview of the Block Editor workflow

    3.x

    The Block Editor provides a dynamic, drag-and-drop interface for adding and arranging content blocks (such as images, text, or custom components) within a Twill entry.

    To implement a block editor, follow these three high-level steps:

    1. Include the block editor form field in your module's form.
    2. Create and define the specific block types you want to support.
    3. Apply the necessary block traits to your Model and Repository to ensure data is correctly handled.
  10. Install Laravel for Twill

    3.x

    To begin setting up a project for Twill, install a fresh Laravel project using Composer. This creates the necessary directory structure and downloads required packages.

    Run the following command in your terminal:

    composer create-project laravel/laravel laravel-twill

    After installation, navigate into the project directory:

    cd laravel-twill

    To run the application locally, you can use Laravel's built-in web server:

    php artisan serve