Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a new Template for Custom component #442

Closed
Schwofel opened this issue Jan 10, 2020 · 4 comments
Closed

Create a new Template for Custom component #442

Schwofel opened this issue Jan 10, 2020 · 4 comments

Comments

@Schwofel
Copy link

How can i add a new template for my custom component?

@travist
Copy link
Member

travist commented Jan 14, 2020

@travist travist closed this as completed Jan 14, 2020
@merobal
Copy link
Collaborator

merobal commented Jan 14, 2020

  1. Create a new TypeScript file.
    Example: custom-template.ts

  2. Define a single function, with one param called ctx. Inside the function define the html. You may reach config via the ctx param.
    Example:

export default function(ctx: any) {
  // console.log(ctx);
  let p = `<div>Lorem Ipsum</div>`;
  return p;
}

  1. Register the template. Do it "somewhere" in the Angular scope, like in the constructor of an NgModule.
    Example:
import customTemplate from './custom-template';
import { Templates } from 'angular-formio';

[...]
export class FormDesignerModule {
  constructor() {
    Templates.current.custom = {
      form: fieldTemplate,
    };
  }
}

  1. You can use this template for your custom formio component. The template will be called "custom" (due to defined as Templates.current.custom)
    See the "Optional: define a template for the element." part in the docs.

If you found this useful I can add this to the wiki at some point.

@hbaldwinRPT
Copy link

Okay but shouldnt it be customTemplate not fieldTemplate? Im doing this and its stating that my template file is not a module. and how do i use this template in my formiocustomcomponent options?

Amazing work on this so far, Cant wait to see how this all works out!

@kievsash
Copy link

How can we create custom template to be able to insert their other builder widgets?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants