Statamic Documentation

website·Indexed 35 days ago

https://statamic.dev/modifiers/

A self-hosted PHP application built as a Laravel package. Documentation covers installation via CLI, Docker, Laravel Herd, and various cloud providers, as well as core concepts, licensing for Core and Pro editions, configuration, and upgrade guides for versions v2 through v6.

Tokens
8.2K
Snippets
44
Records
75
Agent score
72%

What's inside Statamic

  1. Implement custom UI and HTML in Statamic

    Statamic is a 'bring your own HTML' platform. It does not provide a default design, CSS, or JavaScript. Developers are responsible for providing the frontend layer, though Starter Kits can be used to accelerate the process. This makes Statamic a tool for building custom sites rather than a 'no-code' solution for assembly, although the resulting site is easily maintainable by non-developers via the Control Panel.
  2. Understand Statamic's 'Flat-First' data architecture

    Statamic operates in flat file mode by default, meaning content, configurations, and templates are stored as files. This enables end-to-end version control, the ability to manage the site directly in a code editor, and simplified deployment. While Statamic supports relational databases (MySQL, Postgres) or NoSQL solutions (MongoDB, Redis) via its Repositories feature, these should typically only be used when scaling for tens of thousands of records or extremely high traffic.
  3. Migrate Statamic v2 themes and views to v3

    v2-to-v3.md
    The concept of 'themes' has been removed in v3. The site now has a single frontend located in the resources directory. Templates (views) are now consolidated in resources/views instead of being split across templates, layouts, and partials directories.
  4. Retrieve environment variables in config and views

    Use the env() helper function within PHP config files to retrieve environment variables. You can provide a second argument as a default value. Once a variable is mapped in a config file, it can be accessed in views using the {{ config }} tag (Antlers) or the config() helper (Blade).
    // In config/app.php
    'awesome' => env('ENABLE_AWESOME', true),
    {{ config:app:awesome }}
    {{ config('app.awesome') }}
  5. Manage Statamic data storage in existing Laravel apps

    By default, when installed into an existing Laravel application, Statamic stores content as flat files.

    • Database Content: To store content in a database instead of files, refer to the "Storing Content in a Database" guide.
    • Database Users: To keep users in a database, refer to the "Storing Users in a Database in an Existing Laravel App" guide.

    After installation, the following directories are added to the project:

    • content/
    • resources/users/
    • config/statamic/
  6. Install Statamic using the CLI

    The recommended way to install Statamic is via the CLI installer. This requires a local development environment with Composer installed. After installing the CLI globally, you can create a new site project using the statamic new command.
    # Install the Statamic CLI globally
    composer global require statamic/cli
    
    # Create a new site project
    statamic new cyberspace-place
  7. Enable and verify Nginx site configuration

    Test the Nginx configuration for syntax errors, create a symlink to the sites-enabled directory, and reload the Nginx service to apply changes.
    # Test configuration
    sudo nginx -t
    
    # Enable site and reload
    sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
    sudo systemctl reload nginx
  8. Configure Nginx to serve a Statamic site

    Install Nginx and create a site configuration file in /etc/nginx/sites-available/. Ensure the fastcgi_pass directive matches the version of PHP-FPM installed on your system (e.g., php8.3-fpm.sock).
    server {
        listen 80;
        server_name example.com;
        root /var/www/html/example.com/public;
    
        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Content-Type-Options "nosniff";
    
        index index.html index.htm index.php;
        charset utf-8;
    
        set $try_location @static;
    
        if ($request_method != GET) {
            set $try_location @not_static;
        }
    
        if ($args ~* "live-preview=(.*)") {
            set $try_location @not_static;
        }
    
        location / {
            try_files $uri $try_location;
        }
    
        location @static {
            try_files /static${uri}_$args.html $uri $uri/ /index.php?$args;
        }
    
        location @not_static {
            try_files $uri /index.php?$args;
        }
    
        location = /favicon.ico { access_log off; log_not_found off; }
        location = /robots.txt  { access_log off; log_not_found off; }
    
        error_page 404 /index.php;
    
        location ~ \.php$ {
            fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            include fastcgi_params;
        }
    
        location ~ /\.(?!well-known).* {
            deny all;
        }
    }
  9. Set up a local development environment for Statamic

    Depending on your operating system, use the following recommended tools to develop Statamic locally:

    • macOS and Windows: Use Laravel Herd, which provides a native environment including php, composer, and npm.
    • Linux: Manually install php, composer, and npm. Users on Ubuntu or Debian-based systems are encouraged to follow a dedicated Ubuntu installation guide.
  10. Design a flexible content schema in Statamic

    Statamic does not enforce a specific content model. Developers can define their own field names, organize entries into custom collections, and create taxonomies with specific URL patterns.

    Common strategies include:

    • The 'One Big Field' approach: Using the Bard fieldtype to combine content and markup in a single area, potentially adding custom Set blocks.
    • The 'Discrete Field' approach: Breaking content into small, optional fields and using conditional fields to show or hide them based on logic.
  11. Configure a Pages collection manually in Statamic

    When installing Statamic into an existing Laravel app, no content is included. To set up a standard 'Pages' collection for a home page and tree-structured pages, you can either copy the pages.yaml and pages directory from the Statamic GitHub repository or configure it via the Control Panel:

    1. Create a collection named pages.
    2. Set the route to {parent_uri}/{slug}.
    3. Enable the "Orderable" toggle.
    4. Enable the "Expect a root page" toggle.
    5. Create the first entry to serve as the home page.
  12. Install Statamic via the CLI

    Statamic can be installed on macOS, Windows, or Linux provided you have PHP 8.3+ (with required extensions) and Composer installed. The Statamic CLI provides a setup wizard for starter kits, initial user creation, and git initialization.
    # Install the Statamic CLI globally
    composer global require statamic/cli
    
    # Verify installation
    statamic list