{"id":15046376,"url":"https://github.com/tattersoftware/codeigniter4-themes","last_synced_at":"2025-10-26T20:32:36.830Z","repository":{"id":34943580,"uuid":"192931249","full_name":"tattersoftware/codeigniter4-themes","owner":"tattersoftware","description":"Lightweight theme manager for CodeIgniter 4","archived":false,"fork":false,"pushed_at":"2024-01-18T12:20:33.000Z","size":119,"stargazers_count":15,"open_issues_count":4,"forks_count":5,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-02-06T17:44:26.066Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tattersoftware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-20T14:06:53.000Z","updated_at":"2024-09-01T02:49:45.000Z","dependencies_parsed_at":"2024-06-19T17:35:10.947Z","dependency_job_id":"d1349ad6-c6a2-4bbd-96bb-5a72a5823968","html_url":"https://github.com/tattersoftware/codeigniter4-themes","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-themes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-themes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-themes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-themes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tattersoftware","download_url":"https://codeload.github.com/tattersoftware/codeigniter4-themes/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238397255,"owners_count":19465145,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T20:53:02.695Z","updated_at":"2025-10-26T20:32:31.544Z","avatar_url":"https://github.com/tattersoftware.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tatter\\Themes\nLightweight theme manager for CodeIgniter 4\n\n[![](https://github.com/tattersoftware/codeigniter4-themes/workflows/PHPUnit/badge.svg)](https://github.com/tattersoftware/codeigniter4-themes/actions/workflows/test.yml)\n[![](https://github.com/tattersoftware/codeigniter4-themes/workflows/PHPStan/badge.svg)](https://github.com/tattersoftware/codeigniter4-themes/actions/workflows/analyze.yml)\n[![](https://github.com/tattersoftware/codeigniter4-themes/workflows/Deptrac/badge.svg)](https://github.com/tattersoftware/codeigniter4-themes/actions/workflows/inspect.yml)\n[![Coverage Status](https://coveralls.io/repos/github/tattersoftware/codeigniter4-themes/badge.svg?branch=develop)](https://coveralls.io/github/tattersoftware/codeigniter4-themes?branch=develop)\n\n## Quick Start\n\n1. Install with Composer: `\u003e composer require tatter/themes`\n2. Update the database: `\u003e php spark migrate -all`\n3. Seed the database: `\u003e php spark db:seed \"Tatter\\Themes\\Database\\Seeds\\ThemeSeeder\"`\n5. Place theme files in **public/assets/themes/default** \n5. Add theme files to your page, e.g.: `echo view('\\Tatter\\Themes\\Views\\css)`\n\n## Features\n\nProvides convenient theme file organization and display for CodeIgniter 4\n\n## Installation\n\nInstall easily via Composer to take advantage of CodeIgniter 4's autoloading capabilities\nand always be up-to-date:\n* `\u003e composer require tatter/themes`\n\nOr, install manually by downloading the source files and adding the directory to\n`app/Config/Autoload.php`.\n\nOnce the files are downloaded and included in the autoload, run any library migrations\nto ensure the database is setup correctly:\n* `\u003e php spark migrate -all`\n\nYou will also need to seed the database with a default theme:\n* `\u003e php spark db:seed \"Tatter\\Themes\\Database\\Seeds\\ThemeSeeder\"`\n\n## Dependencies\n\n`Themes` relies heavily on these libraries; be sure you are familiar with their own\nrequirements and installation process.\n* [Tatter\\Assets](https://github.com/tattersoftware/codeigniter4-assets) handles asset discovery and HTML tag injection\n* [Tatter\\Preferences](https://github.com/tattersoftware/codeigniter4-preferences) allows for user- or session-specific theme changing \n* [CodeIgniter\\Settings](https://github.com/codeigniter4/settings) (a dependency of `Preferences`) loads and stores theme preferences into persistent storage\n\nIf you plan on allowing users to change their own themes then you will also need to include\nan authentication library the provides `codeigniter4/authentication-implementation` (no other\nconfiguration necessary).\n\n\u003e Read more about CodeIgniter Authentication in the [User Guide](https://codeigniter.com/user_guide/extending/authentication.html).\n\n## Usage\n\n*This library assumes you already have the asset files (CSS and JavaScript) used by your themes.*\n\nThemes are managed via the database and configured for your application using Filters.\n\n### Managing Themes\n\nTheme files all go into a directory relative to the config property `$directory` from\n`Tatter\\Assets` (default is **public/assets/**), as defined by a theme's `path`. E.g.\n\n* public/assets/themes/default/styles.css\n* public/assets/themes/default/script.js\n* public/assets/themes/dark/header.css\n* public/assets/themes/dark/fonts.css\n* public/assets/themes/perky/Perky.CSS\n\nEach theme is an entry in the database `themes` table with the following properties:\n\n* `name`: A short, unique name used for theme lookup and display, e.g. \"Aquatic Journey\"\n* `path`: The path (relative to the `Assets` directory) to the publicly-available theme files, e.g. \"themes/aquatic/\"\n* `description` (optional): A brief description of this theme's features, mostly useful for allowing user selection, e.g. \"A blue theme with deep hues and liquid borders\"\n* `dark`: Whether this theme is dark (light text, dark backgrounds) or not, e.g. `true`\n\nYou may use the supplied model (`Tatter\\Themes\\Models\\ThemeModel`) to create new themes or\nreturn entities (`Tatter\\Themes\\Entities\\Theme`). The library comes with the `ThemeSeeder`\nwhich will create an initial \"Default\" theme for you at **public/assets/themes/default/**.\nThere is also a `themes:add` Spark command to guide you through loading themes from CLI.\n\n### Selecting a Theme\n\nThe current theme is determined as follows:\n\n1. Is there an authenticated user? Check `Preferences` for that user's theme preference\n2. No authenticated user? Check the Session for a theme preference\n3. Neither of above? Check `Settings` for a stored persistent theme\n4. None of the above? Fall back on the config file: `config('Preferences')-\u003etheme` (default value \"Default\")\n\nLikewise, you can set the current theme using the corresponding methods (in priority order):\n\n1. `preference('theme', $themeName)` (with authenticated user)\n2. `preference('theme', $themeName)` (without authenticated user)\n3. `setting('Preferences.theme, $themeName)`\n4. Create or edit **app/Config/Preferences.php** and add: `public $theme = 'theme_name';`\n\nTo assist with methods 1 \u0026 2 this library comes with a tiny module to display a form and\nprocess user input. You can add the form to an existing page with the Form View:\n```html\n\u003cdiv class=\"form\"\u003e\n\t\u003c?= view('Tatter\\Themes\\Views\\form') ?\u003e\n\u003c/div\u003e\n```\n\n...or add the preconfigured `\u003cselect\u003e` field to an existing form:\n\n```html\n\u003cform name=\"user-settings\" action=\"\u003c?= site_url('users/settings') ?\u003e\" method=\"post\"\u003e\n\tDisplay name:\n\t\u003cinput type=\"text\" name=\"name\"\u003e\n\n\tPage theme:\n\t\u003c?= view('Tatter\\Themes\\Views\\select') ?\u003e\n\n\t\u003cinput type=\"submit\" value=\"submit\"\u003e\n\u003c/form\u003e\n```\n\nYou can pass these additional parameters to the view:\n* `$class`: A CSS class to apply to the `\u003cselect\u003e` field. Default: *none*\n* `$auto`: Whether the form should submit as soon as the select field is changed. Default: `true`\n* `$selected`: The theme to show as currently chosen in the select field: Default: current theme\n\n### Applying Themes\n\nOnce your files are in place and your theme is defined in the database you need to apply the\ntheme to your application routes using [Filters](https://codeigniter4.github.io/CodeIgniter4/incoming/filters.html).\nThis library activates the `ThemesFilter` for you on installation (assuming module discovery\nis enabled, which is the default) under the alias `themes`. In simple cases you will want to\napply the filter to your entire site via **app/Config/Filters.php**:\n\n```php\n    /**\n     * List of filter aliases that are always\n     * applied before and after every request.\n     *\n     * @var array\n     */\n    public $globals = [\n        'before' =\u003e [\n            // 'honeypot',\n            // 'csrf',\n            // 'invalidchars',\n        ],\n        'after' =\u003e [\n            'themes',\n        ],\n    ];\n```\n\nFor more nuanced use, pass the filter to your route definitions in **app/Config/Routes.php**:\n```php\n$routes-\u003eadd('shop/(:segment)', 'ShopController::index', ['filter' =\u003e 'themes']);\n```\n\n`ThemesFilter` will apply the current theme by default, but you may specify a theme or themes\nby name to use those instead:\n```php\n$routes-\u003eadd('heroes/(:segment)', 'HeroController::$1', ['filter' =\u003e 'themes:Heroic']);\n```\n\n## Additional Components\n\n### CLI\n\nThe library comes with two CLI commands, `themes:list` and `themes:add` to ease working\nwith themes in the database.\n\n### Helper\n\nThe Theme Helper is loaded automatically when you apply `ThemeFilter`, but should you need\nto load it manually include it your controllers or boot config: `helper('themes')`.\n\nThis provides a helper function to return the current theme as a `Theme` entity:\n```php\n$theme = theme();\necho 'Current theme is ' . $theme-\u003ename . ': \"' . $theme-\u003edescription . '\"';\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftattersoftware%2Fcodeigniter4-themes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftattersoftware%2Fcodeigniter4-themes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftattersoftware%2Fcodeigniter4-themes/lists"}