5

When I have a folder setup for template partials, is there a way I could automatically populate a drop-down with the list of templates in that folder?

This would be useful in the case where I have a complex matrix field set, and would like to select a partial to render or include along with the block's content.

If the drop-down were automatically populated, it would eliminate a lot of time setting up the drop-downs in the backend, and would make it much easier to deploy new feature sets across many Craft based sites as they are developed or improved.

2 Answers 2

5

try using this:

https://github.com/lukeholder/dir

to populate this plugin with the template names:

https://github.com/lewisjenkins/craft-lj-dynamicfields/

2
  • Works great Luke. {% for template in craft.dir.templates('some/folder') %} { "value":"{{ template }}" , "label":"{{ template }}" }{% if not loop.last %},{% endif %} {% endfor %} Jun 18, 2014 at 2:54
  • thanks @pixelJitsu i still think there is a good market for a template selector field plugin, but this is a good stopgap. :) Jun 19, 2014 at 3:57
6

This would be a good task for a plugin.

You'd essentially need to build the plugin to do a couple of things:

(1) Use PHP in a service to list the contents of a directory. Once you have that list, you'd then need to...

(2) Deliver that information to the front end via a custom field type. You can then use your new custom field type wherever you'd like.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.