Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 8459d7c

Browse files
Example added on how to overwrite a knockoutjs html file (#8367)
* Added an example for overwriting a knockoutjs .html template file in requirejs-config.js by using paths * removed the image * fixed lint errors * fixed lint errors * Review comments * Added spaces after list hyphen * review comments * lint errors * Apply suggestions from code review Co-authored-by: Jeff Matthews <[email protected]> * split a point for clarity * lint errors * lint errors * lint errors * formatting errors * Fixed formatting Co-authored-by: Jeff Matthews <[email protected]>
1 parent f8b5958 commit 8459d7c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/guides/v2.3/javascript-dev-guide/javascript/requirejs.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,38 @@ paths: {
6262
}
6363
```
6464

65+
Consider the example of overwriting an HTML file in the adminhtml.
66+
In this example, the `max-length` value of the text-box in the `adminhtml` is altered. The HTML file is located at `vendor/magento/module_ui/view/base/web/templates/form/element/input.html`.
67+
68+
1. Create a `requirejs-config.js` file under `app/code/<Vendor_Name>/<Module_Name>/view/base/` and add the following code:
69+
70+
```javascript
71+
var config = {
72+
paths: {
73+
'ui/template/form/element/input': '<vendor_name>_<module_name>/template/form/element/input'
74+
}
75+
};
76+
```
77+
78+
1. Create an `input.html` file under `app/code/<Vendor_Name>/<Module_Name>/view/base/web/template/form/` and copy the contents of the `input.html` file from the `module_ui` template file.
79+
1. Change the maxlength value to `512`, which was originally set to `256`.
80+
1. Upgrade the Magento application:
81+
82+
```bash
83+
bin/magento setup:upgrade
84+
```
85+
86+
1. Generate the dependency injection configuration:
87+
88+
```bash
89+
bin/magento setup:di:compile
90+
```
91+
92+
1. Confirm the modification by inspecting the element source code and check the `maxlength` value, which should be `512` as specified in the template.
93+
94+
{:.bs-callout-info}
95+
The path for `Magento_Ui/templates` is set to be `ui/template` in the `requirejs-config.js` module of `module_ui`, hence `ui/template` is used for specifying the path. If no paths are set, `<module_name>/templates` should be used.
96+
6597
### deps {#requirejs-config-deps}
6698

6799
The `deps` configuration is used to add a dependency. It can either be used directly under `var config = {}` or under a [shim configuration](#requirejs-config-shim). Adding modules under an independent `deps` configuration will load the specified modules in all pages.

0 commit comments

Comments
 (0)