1

I'm using Sprout Reports, which makes this reference:

Use the Form Macros supported by the Craft CP to keep consistent with the Craft UI. Sprout Reports will import the Craft CP Form Macros. Your Settings Template can look like this where the imported forms variable includes all Craft form macros defined in craft/app/templates/_includes/forms.html

Where in the world do I find this information? And is it documented anywhere?

My inquiry was prompted by needing to know how to make a form field selection required.

1
  • 1
    Here's an example of Craft using a macro to make a Text field required in the section settings. The select field would be handled the same way – adding the required: true, attribute to the selectField macro. Jun 3 at 18:07
2

The Craft Form Macro file is in the Craft package.

The forms.html file is the macro file, and that file loads several other templates depending on which form macro is being used.

vendor/craftcms/cms/src/templates/_includes/forms.html

You can see the individual files in this directory:

vendor/craftcms/cms/src/templates/_includes/forms/

Unfortunately, there is no documentation on how these work. I'd recommend to start by getting familiar with Twig macros, and then you can look through the vendor/craftcms/cms/src/templates folder, various plugin template folders, or the Sprout Reports example files to see several examples of how macros are being used.

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.