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

Example added on how to overwrite a knockoutjs html file #8367

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/guides/v2.3/javascript-dev-guide/javascript/requirejs.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,38 @@ paths: {
}
```

Consider the example of overwriting an HTML file in the adminhtml.
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`.

1. Create a `requirejs-config.js` file under `app/code/<Vendor_Name>/<Module_Name>/view/base/` and add the following code:

```javascript
var config = {
paths: {
'ui/template/form/element/input': '<vendor_name>_<module_name>/template/form/element/input'
}
};
```

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.
1. Change the maxlength value to `512`, which was originally set to `256`.
1. Upgrade the Magento application:

```bash
bin/magento setup:upgrade
```

1. Generate the dependency injection configuration:

```bash
bin/magento setup:di:compile
```

1. Confirm the modification by inspecting the element source code and check the `maxlength` value, which should be `512` as specified in the template.

{:.bs-callout-info}
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.

### deps {#requirejs-config-deps}

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.
Expand Down