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.

5

try using this:

https://github.com/lukeholder/dir

to populate this plugin with the template names:

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

|improve this answer|||||
  • Works great Luke. {% for template in craft.dir.templates('some/folder') %} { "value":"{{ template }}" , "label":"{{ template }}" }{% if not loop.last %},{% endif %} {% endfor %} – Steve Adams Jun 18 '14 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. :) – Luke Holder Jun 19 '14 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.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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