Create/Edit Module with a Text Editor
Step 1:
Set up the project solution.We have gotten the project from the Getting started template itself.
Øset up the folder structure to organize your modules. Modules are sets of includes—rules that determine what you want to serialize and how you want to interact with things you pull and push in your solution.
ØCreate a folder titled TestModule
Step 2:
ØOpen the MyProject project in Visual Studio Code.
ØNavigate to the sitecore.json file.
Change this to "src/*/*.module.json"
Note: The Sitecore.json file is used to control how Sitecore serialization behaves. The modules section of this file is used by Sitecore serialization to locate all modules in your solution. The default configuration only refers to a single module, but we can change it to use wildcards (*/*) to locate all modules in your solution.
Step 3:
Under the src\TestModule node in your project, create a file for your module named TestModule.module.json.
add the following code:
You have now created a module called TestModule.
Note: When developing a solution, make sure that the location of your module matches the path of the glob in your sitecore.json file (default glob is src/*/*.module.json). If it does not, add the path to the sitecore.json file.
Configure Item Include
Step 1:
Open the TestModule.module.json file and add it
{
"namespace": "TestModule",
"items": {
"includes": [
{
"name": "Colors include",
"path": "/sitecore/content/MySC10Project/Colors"
}
]
}
}
This include indicates that this module will serialize the Plants item and its descendants (the scope is set to Item and Descendants by default).
Define Rules
Open the TestModule.module.json
Add this rule
"rules": [
{
"path": "/Purple",
"scope": "ignored"
}
]
Then the whole json would look like this
{
"namespace": "TestModule",
"items": {
"includes": [
{
"name": "Colors include",
"path": "/sitecore/content/MySC10Project/Colors",
"rules": [
{
"path": "/Purple",
"scope": "ignored"
}
]
}
]
}
Serialize Items
dotnet sitecore ser -h
Pull Items
When we run the serialization command, it will execute the includes and rules of the modules we have created.
First , test the functionality before proceeding
dotnet sitecore ser pull -w
The -w allows you to see what would be executed, without actually executing.
Run dotnet sitecore ser pull.
I have added the rules for ignoring purple color so it’s not serialized.
No comments:
Post a Comment