Jump to content

Select Field Renderer from directory?


nico65
 Share

Recommended Posts

Hello I just saw, that you can render fields and repeaterblocks within their own templates.
That's pretty Cool!

I have a nested repeater block "gcb" that is rendered in:
/site/templates/fields/gcb.php

But this is just a switch, because in the repeater block is a selectfield,
which tells the repeater block which sub field template it should use to render.

E.g.: plain, spezialitaeten, tools

These templates are all in the "gcb" subfolder:
/site/templates/fields/gcb/plain.php
/site/templates/fields/gcb/spezialitaeten.php 
/site/templates/fields/gcb/tools.php 

My Question now is, is there a easy solution to have a selectbox that lets you select between the file in the folder:
/site/templates/fields/gcb/

Because right now, I have to update this selectfield manually, with the possible options.

Link to comment
Share on other sites

You could use my FieldtypeDropdownDynamic in conjunction with a snippet of code that iterates the gcb directory for php files like the following (untested):

return array_map(
	function($file) {
		return array("label" => $file, "name" => $file);
	},
	array_filter(
		scandir($config->paths->templates . "gcb"),
		function($found) {
			return substr($found, -4) == ".php";
		}
	)
);

 

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...