superbig / craft3-templateselect
A fieldtype that allows you to select a template from a dropdown.
Installs: 41 236
Dependents: 0
Suggesters: 0
Security: 0
Stars: 17
Watchers: 3
Forks: 9
Open Issues: 3
Type:craft-plugin
Requires
- craftcms/cms: ^5.0.0
Requires (Dev)
- craftcms/ecs: dev-main
- craftcms/phpstan: dev-main
- craftcms/rector: dev-main
This package is auto-updated.
Last update: 2024-11-13 22:53:40 UTC
README
A fieldtype that allows you to select a template from the site templates folder.
Requirements
This plugin requires Craft CMS 4.0 or later.
Installation
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project
-
Then tell Composer to load the plugin:
composer require superbig/craft3-templateselect
-
In the Control Panel, go to Settings → Plugins and click the “Install” button for Template Select.
Configuring Template Select
Create a new field and choose field type Template Select.
In the field settings, you can limit the list of available templates to a subfolder of the Craft templates folder. The path is relative, i.e. subfolder/anotherfolder. This may also be set to an ENV variable.
In the field settings, you can choose to make the template names more user friendly. In the field, the list will be improved by changing the following:
- file extensions will be removed
- the file names will be capitalized and spaced for readability
- folders will be separated by ›
Using Template Select
Output the chosen template name:
{{ entry.fieldHandle }}
Include/Embed the chosen template:
{% include entry.fieldHandle %}
Include the template including subfolder if set:
{% include entry.fieldHandle.withSubfolder() %}
This is a alias for the following:
{{ entry.templateWithSubfolder.template(true) }}
Output the subfolder name:
{{ entry.fieldHandle.subfolder() }}
Output the filename without path:
{{ entry.fieldHandle.filename() }}
Brought to you by Superbig