This repository was archived by the owner on Nov 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Added documentation about the Breadcrumbs widget #5228
Merged
jeff-matthews
merged 7 commits into
magento:master
from
serhiyzhovnir:add-breadcrumbs-widget-documentation
Aug 26, 2019
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9a435b6
Add breadcrumbs widget documentation
1a9fa45
Improved the explanation of title and label options
39ddf6c
Adjusted the breadcrumbs widget documentation
9bf46ed
Remove trailing spaces
c1f0d54
Merge branch 'master' into add-breadcrumbs-widget-documentation
jeff-matthews 5816914
Fixed the Breadcrumbs list link
6d5adae
Merge branch 'master' into add-breadcrumbs-widget-documentation
jeff-matthews File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
guides/v2.2/javascript-dev-guide/widgets/widget-breadcrumbs.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
--- | ||
group: javascript-developer-guide | ||
subgroup: 3_Widgets | ||
title: Breadcrumbs widget | ||
contributor_name: Atwix | ||
contributor_link: https://www.atwix.com/ | ||
--- | ||
|
||
## Overview | ||
jeff-matthews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The Breadcrumbs [widget](https://glossary.magento.com/widget/) allows building a list of links which should show where you are in relation to other pages in the store. | ||
jeff-matthews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The Breadcrumbs widget can be used only on the frontend area. | ||
|
||
The widget source file is [`<Magento_Theme_module_dir>/view/frontend/web/js/view/breadcrumbs.js`][] | ||
jeff-matthews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The Breadcrumbs widget template source file is [`<Magento_Theme_module_dir>/view/frontend/web/templates/breadcrumbs.html`][] | ||
jeff-matthews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Initialize the Breadcrumbs widget | ||
|
||
For information about how to initialize a widget in a JS component or `.phtml` template, see the [Initialize JavaScript][] topic. | ||
|
||
Generally the Breadcrumbs widget is instantiated like following: | ||
jeff-matthews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```javascript | ||
$('#breadcrumbs').breadcrumbs(); | ||
``` | ||
|
||
Where: | ||
|
||
- `#breadcrumbs` is the selector of the block element for which Breadcrumbs is initialized. | ||
jeff-matthews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Phtml template file examples using script: | ||
jeff-matthews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```html | ||
<script> | ||
require([ | ||
'jquery', | ||
'breadcrumbs' | ||
], function ($) { | ||
'use strict'; | ||
|
||
$('#breadcrumbs').breadcrumbs(); | ||
}); | ||
</script> | ||
``` | ||
|
||
## Breadcrumb List | ||
|
||
The Breadcrumb List is used to configure the breadcrumbs list. | ||
jeff-matthews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The Breadcrumb List represents a simple array which stores breadcrumbs items. | ||
jeff-matthews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The Breadcrumb List source file is [`<Magento_Theme_module_dir>/view/frontend/web/js/model/breadcrumb-list.js`][] | ||
jeff-matthews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The Breadcrumb widget uses the Breadcrumbs List to configure a list of breadcrumbs which should be rendered. | ||
|
||
The Breadcrumb List should be configured before Breadcrumbs widget initialization. After Breadcrumbs widget initialization the Breadcrumb List does not affect the rendered list of breadcrumbs. | ||
jeff-matthews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Code example of adding a new breadcrumb item to the Breadcrumb List: | ||
jeff-matthews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```html | ||
<script> | ||
require([ | ||
'Magento_Theme/js/model/breadcrumb-list' | ||
], function (breadcrumbList) { | ||
'use strict'; | ||
|
||
var breadcrumbs = [ | ||
{ | ||
'name': 'some-page-1', | ||
'link': '/some/path/1', | ||
'title': 'Link title for page 1', | ||
'label': 'Some page 1' | ||
}, | ||
{ | ||
'name': 'some-page-1', | ||
'link': '/some/path/2', | ||
'title': 'Link title for page 1', | ||
'label': 'Some page 2' | ||
} | ||
]; | ||
|
||
breadcrumbs.forEach(function (breadcrumb) { | ||
breadcrumbList.push(breadcrumb); | ||
}); | ||
}); | ||
</script> | ||
``` | ||
|
||
### Breadcrumb List Item Options | ||
|
||
The Breadcrumb List Items should have the following structure: | ||
|
||
| Option | Description | Type | | ||
| --- | --- | --- | | ||
| `name` | The class of a breadcrumb item. | String | | ||
| `link` | The URL link of a breadcrumb item. | String | | ||
| `title` | The title of a breadcrumb item link. | String | | ||
jeff-matthews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| `label` | The label of a breadcrumb item. | String | | ||
|
||
The Breadcrumb List Item Options in the [HTML](https://glossary.magento.com/html): | ||
|
||
 | ||
|
||
## Code sample | ||
|
||
The following example shows how to initialize the Breadcrumb widget and pass breadcrumbs items to the [Breadcrumbs list](#breadcrumb_list). | ||
jeff-matthews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```html | ||
<div class="breadcrumbs" id="breadcrumbs-example"></div> | ||
<script> | ||
require([ | ||
'jquery', | ||
'Magento_Theme/js/model/breadcrumb-list', | ||
'breadcrumbs' | ||
], function ($, breadcrumbList) { | ||
'use strict'; | ||
|
||
var breadcrumbs = [ | ||
{ | ||
'name': 'some-page-1', | ||
'link': '/some/path/1', | ||
'title': 'Link title for page 1', | ||
'label': 'Some page 1' | ||
}, | ||
{ | ||
'name': 'some-page-1', | ||
'link': '/some/path/2', | ||
'title': 'Link title for page 1', | ||
'label': 'Some page 2' | ||
} | ||
]; | ||
|
||
// adding breadcrumbs to the Breadcrumb List | ||
breadcrumbs.forEach(function (breadcrumb) { | ||
breadcrumbList.push(breadcrumb); | ||
}); | ||
|
||
// Breadcrumbs widget initialization | ||
$('#breadcrumbs-example').breadcrumbs(); | ||
}); | ||
</script> | ||
``` | ||
|
||
### Result | ||
|
||
The result is the breadcrumbs block with three items. | ||
|
||
 | ||
|
||
<!-- Link Definitions --> | ||
[Initialize JavaScript]: {{page.baseurl}}/javascript-dev-guide/javascript/js_init.html | ||
[`<Magento_Theme_module_dir>/view/frontend/web/js/view/breadcrumbs.js`]: {{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Theme/view/frontend/web/js/view/breadcrumbs.js | ||
[`<Magento_Theme_module_dir>/view/frontend/web/js/model/breadcrumb-list.js`]: {{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Theme/view/frontend/web/js/model/breadcrumb-list.js | ||
[`<Magento_Theme_module_dir>/view/frontend/web/templates/breadcrumbs.html`]: {{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Theme/view/frontend/web/templates/breadcrumbs.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../v2.2/javascript-dev-guide/widgets/widget-breadcrumbs.md |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.