Peter Knight Posted March 8, 2022 Share Posted March 8, 2022 Hi Is there a field type in the Core which will allow be to select one (or more) files within the PW file system? For context... I want to create two stand-alone PHP files which contain simple HTML as follows Call-to-Action-01.php would be <h2>Call us</h2> Call-to-Action-02.php would be <h2>Email us</h2> These would be stored within the PW /templates directory (I think). I then want to use RepeaterMatrix to select one or both and output them into my template where necessary. I was then looking at the $files->render() method and have the following working <?php $string = $files->render($Call-to-Action01.php); ?> So that's a good start but now how to select ? Thanks ? Link to comment Share on other sites More sharing options...
aagd Posted March 8, 2022 Share Posted March 8, 2022 In the RepeaterMatrix field create two repeater matrix item types: cta1 & cta2. They don't even have to have any fields, i guess. In the template file that should output the repeater items you can output them like this: <?php foreach($page->repeater_matrix_field as $item){ if ($item->type == "cta1"){ echo wireRenderFile("Call-to-Action01.php"); } if ($item->type == "cta2"){ echo wireRenderFile("Call-to-Action02.php"); } } ?> RepeaterMatrix is a pro module, though. Not Core. 2 Link to comment Share on other sites More sharing options...
bernhard Posted March 8, 2022 Share Posted March 8, 2022 3 hours ago, Peter Knight said: Is there a field type in the Core which will allow be to select one (or more) files within the PW file system? Yes, you can use InputfieldTextTags https://processwire.com/blog/posts/pw-3.0.177/ But it would be a lot easier to use HannaCode or a custom Textformatter module which replaces [file=foo-bar.php] with the content of the file foo-bar.php 1 Link to comment Share on other sites More sharing options...
Peter Knight Posted March 9, 2022 Author Share Posted March 9, 2022 20 hours ago, aagd said: In the RepeaterMatrix field create two repeater matrix item types: cta1 & cta2. They don't even have to have any fields, i guess. In the template file that should output the repeater items you can output them like this: <?php foreach($page->repeater_matrix_field as $item){ if ($item->type == "cta1"){ echo wireRenderFile("Call-to-Action01.php"); } if ($item->type == "cta2"){ echo wireRenderFile("Call-to-Action02.php"); } } ?> RepeaterMatrix is a pro module, though. Not Core. Thanks @aagd. Good idea and certainly something I'm about to explore. I used 2 examples but I'll probably at some stage end up with a lot more. My concern is about scalability here and having to create a field to associate with each file. Ideally I'd love a file select field that I can simply point at a directory. Link to comment Share on other sites More sharing options...
bernhard Posted March 9, 2022 Share Posted March 9, 2022 17 minutes ago, Peter Knight said: Ideally I'd love a file select field that I can simply point at a directory. Link to comment Share on other sites More sharing options...
Peter Knight Posted March 9, 2022 Author Share Posted March 9, 2022 18 hours ago, bernhard said: Yes, you can use InputfieldTextTags https://processwire.com/blog/posts/pw-3.0.177/ But it would be a lot easier to use HannaCode or a custom Textformatter module which replaces [file=foo-bar.php] with the content of the file foo-bar.php Thanks @bernhard I've been trying this and much to my surprise, I have it working as follows. Have yet to try it within a Repeater Matrix for the moment. <?php $myfile = $page->fieldtypeselectfile; ?> <?php echo wireRenderFile("$myfile");?> I did find a bug whereby this only seems to scan files within the template folder and not a custom directory but I'll mention that on the main Module thread. Thanks. Link to comment Share on other sites More sharing options...
lokomotivan Posted March 11, 2022 Share Posted March 11, 2022 https://github.com/kreativan/FieldtypeFolderOptions Maybe this custom field type can help or give u an idea, no multiselect support. Define the folder, and field will let u select files from it... then $files->include("my_folder/{$page->my_field_name}.php"); 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now