Git Product home page Git Product logo

craft3-templateselect's Introduction

Template Select plugin for Craft CMS

A fieldtype that allows you to select a template from the site templates folder.

Screenshot

Requirements

This plugin requires Craft CMS 4.0 or later.

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:

     cd /path/to/project
    
  2. Then tell Composer to load the plugin:

     composer require superbig/craft3-templateselect
    
  3. 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.

Screenshot

Screenshot

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 ›

Screenshot

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

craft3-templateselect's People

Contributors

brandonkelly avatar karl456 avatar okolvik-avento avatar sjelfull avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

craft3-templateselect's Issues

Description of template.

I have a lot of templates that user can select. It is very hard to them to remember every single of them and it is hard no me to select a name for the templates that describe them. If I want to make a good description the name become really long.

It is possible to make some kind a Description field/col/zone where it is possible to write a description for the template?

Craft 4 Support

Hi, Is this plugin going to be upgraded to support Craft V4? Any timeline for this?
Thanks in advance.

Use a separate template path.

My idea is to make one matrix field with several components that can be used on many places. For that reason I want to have all my template, that are able to select, in one separated folder called components. In that folder I want to have sub-folders that contains all possible template for each component. Something like this:

project structure

So I add the template select field and set the sub-folder to component/textAndImage/. So when I go to my Homepage and select a template imageOnLeft.twig save it, and then I try to load the page I get this error:

Unable to find the template “imageOnLeft.twig” in "homepage/_entry" at line 5.

So instead to include component/textAndImage/imageOnLeft it just include imageOnLeft.twig.

Is it possible somehow to include the Limit to subfolder + Selected template instead just Selected template?

Template path issue on Windows with Laravel Valet

I am trying to use the extension for one of the project that I just start to work. The idea is to put template select field in a matrix field and select a template for each matrix component. So here is the configuration of the matrix field:

matrix field configuration

First I notice that I get the absolute path in the field when I am in the entry instead just the stripped filenames:

used in entry

I was think that this is some strange bug that will not affect me when I used it in the template. But I was wrong. When i try to open the page in the browser i get this:

loading the template

So I am on Windows 10 and using vitr/valet4windows

FR: Use autosuggest component for template selection

Hi there,

Craft has a nice built-in autosuggest component which works great for template selection. I'm familiar with it because the Vizy field uses it to great effect.

image

My feature request/suggestion is to follow this same approach and use Craft's built in autosuggest component, to provide an improved UI for template selection.

I've added this in a Pull Request for you to consider.
It needs testing and I've only checked it on Craft 4, but please let me know what you think.

FR: Template subfolder variable

Could you please add the option to output the selected template's full path or subfolder so in a front end template this doesn't have to be hardcoded?

so instead of {% include '_mysubfolder/' ~ entry.template %}

maybe {% set template = entry.template %}
then {% include template.filepath %}
or {% include template.subfolder ~ template %}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.