Custom components
Last updated
Last updated
Here's a step-by-step example on how to create a custom component.
This feature is intended to Moodle administrators, not to content creators.
Go to Site administration → Plugins → Text editors → TinyMCE editor → Components for Learning (C4L) and then click on the Custom Components section.
Select the value 1
in the customcompcount
field and press the Save changes
button; by doing this, all the necessary fields to create our first custom component will appear on the screen.
First, we will place our component's CSS classes in the custompreviewcss
field. The CSS classes we add in this field will allow us to view our components within the Tiny editor when we are in edit mode.
Upload to the customimagesbank
field the image meant to appear within our component.
Click on the customcompenable1
option to activate our component. This field allows us to enable or disable the components we have created.
In the customcompname1
field, enter the text ChatGPT
. This field allows us to set the text that will appear on the button of our component - 15 characters maximum."
In the customcompicon1
field, upload the icon that will appear on the button of our component. If we do not have an icon, the system will automatically assign one.
In the customcomptext1
field, enter the text that will be used as a 'placeholder' in the component.
What’s the best way to know if an animal is a mammal?
In the customcompcode1
field, enter the component's HTML code.
Here's some special elements that appear in the previous HTML code snipped:
{{CUSTOMCLASS}} - Mandatory in order for the component to actually work.
{{chatgpt-component.svg}} - The images added in the Step 5.
{{PLACEHOLDER}} - The text included in the Step 9.
Activate the variants by clicking the customcompvariant1
option. Custom components can only use the full width
variant.
In the customcompsortorder1
field, enter the value 1
. This parameter allows us to display the components in the order that suits us best. Components with smaller numbers will appear first.
Press the Save changes
button to save your changes.
Check that the created component appears within the C4L plugin's Custom
tab.
In order for the components to be displayed correctly outside the Tiny editor, we must also copy the same CSS classes we used in Step 3 into Site administration → Appearance → Additional HTML → Within HEAD (the additionalhtmlhead
field). Your CSS must be wrapped inside of a <style></style>
tag (both opening and closing tags), in order to generate valid HTML code. Save the changes by pressing the Save changes
button.