As a Sitecore developer, you know that time is always of the essence when it comes to building and maintaining websites. Whether you’re working on a new project or troubleshooting an issue, having quick access to the most frequently used commands and syntax can be a game changer.
You know that developers love a good Cheat Sheet.
And since I started working with Sitecore I’ve been taking notes of the commands that I use every day. Then I think “why don’t I share it with the community”? So I improved my list of commands and created this Cheat Sheet with the most used commands in Sitecore XP 10.3.
With a comprehensive list of commands for Sitecore HTML Helper, xConnect API, Docker, and Sitecore CLI, you can streamline your development process and speed up your workflow.
So I created a PDF file with my Cheat Sheet:
Feel free to download and use it:
What are the commands and why have I chosen those topics?
If you don’t wanna to download the PDF file, here are all the commands contained in the Cheat Sheet and the answers for each topic as well:
1) Sitecore HTML Helper
If you’re a Sitecore developer you will likely build components. And build components mean create Views. So here you have a huge list with the most used Sitecore HTML methods helper that you’ll use frequently.
Command | Description |
---|---|
@Html.Sitecore().Field(“FieldName”) | Renders the field with the specified name on the current item |
@Html.Sitecore().Field(“FieldName”, YourItem) | Renders the field with the specified name on the provided item |
@Html.Sitecore().Field(“FieldName”, new { Text = “Default Text” }) | Renders the field with the specified name on the current item with the provided default text |
@Html.Sitecore().Field(“FieldName”, new { DisableWebEditing = true }) | Renders the field with the specified name on the current item with web editing disabled |
@Html.Sitecore().Field(“Image”, YourItem) | Renders the image field with the specified name on the provided item |
@Html.Sitecore().Field(“Image”, YourItem, new { w = 300, h = 200 }) | Renders the image field with the specified name on the provided item with the specified width and height |
@Html.Sitecore().Field(“Link”, YourItem) | Renders the link field with the specified name on the provided item |
@Html.Sitecore().Link(“FieldName”, YourItem) | Renders the link field with the specified name on the provided item |
@Html.Sitecore().BeginField(“FieldName”, YourItem) | Begins a field with the specified name on the provided item |
@Html.Sitecore().EndField() | Ends the current field started by BeginField |
@Html.Sitecore().Rendering(“{ItemID}”) | Renders the rendering with the specified ID |
@Html.Sitecore().Rendering(“{ItemID or Name of the Rendering}”, new { DataSource = “{Item ID}” }) | Renders the rendering with the specified Item ID or name on the item with the specified ID. Also, adds a default datasource. |
@Html.Sitecore().CurrentRendering | Gets the current rendering from Context |
@Html.Sitecore().RunPipeline(“Your-Pipeline”, your-parameters); | Used to execute a specific Sitecore pipeline, passing in any necessary data as parameters. |
@Html.Sitecore().Placeholder(“YourPlaceholder”) | Renders the specified placeholder |
@Html.Sitecore().DynamicPlaceholder(“YourPlaceholder”) | Renders the content of the specified dynamic placeholder |
@Html.Sitecore().FormHandler(“Your-Form-Name”, “Your-Submit-Button”) | Used to handle form submissions. used to specify the handler for a form with the name “Your-Form-Name” and the action “Your-Submit-Button”. When the user submits the form, Sitecore will execute the specified action, in this case, “Your-Submit-Button”. |
@Html.Sitecore().CurrentItem | Gets the current item |
@Html.Sitecore().ViewRendering(“path”, new { Title = “Your Title”, Description = “Your Description”}) | Render a view statically. The first parameter specifies the path to the view, and the second parameter passes data to the rendering. |
@Html.Sitecore().ControllerRendering(“controller name”, “action name”) | Render a controller statically. It executes a controller action and renders the result. The first parameter specifies the name of the controller, and the second parameter specifies the name of the action. |
@Html.BeginEditFrame(“My Edit Frame”, YourItem, “Edit Frame Description”, new { Buttons = “save, cancel” }) | Begins an edit frame for the provided item with the specified name, description, and button options. Include Glass Mapper lib. |
@Html.Sitecore().VisitorIdentification() | Renders the visitor identification tag |
@Html.Sitecore().IsExperienceEditorEditing | Gets a boolean value indicating whether the current request is being executed in Experience Editor mode |
@Html.Sitecore().HasValue(“FieldName”, YourItem) | Gets a boolean value indicating whether the specified field on the provided item has a value |
Section 2: xConnect
xConnect is an essential component of Sitecore XP that allows you to collect, store, and access customer interaction data from various sources. Here I bring the most important xConnect commands for communicating with the xConnect API, where you can check if xConnect is Working, check Contacts, Facets and Interactions.
Method | URL | Description |
---|---|---|
GET | https://your-xconnect-url/ | Returns a timestamp indicating that xConnect is working. |
GET | https://your-xconnect-url/odata/$metadata | Returns the metadata document that describes the structure of the xConnect data service. This can be used to query the available entity types and their properties. |
GET | https://your-xconnect-url.com/odata/contacts | Retrieves a list of all contacts in xConnect. |
POST | https://your-xconnect-url.com/odata/contacts | Insert a new contact in xConnect. |
GET | https://your-xconnect-url.com/odata/contacts/{your-contact-id} | Retrieves information about a specific contact identified by their contact identifier |
GET | https://your-xconnect-url.com/odata/contacts/{your-contact-id}?$expand=your-facet | Retrieves a specific facet for a given contact identified by their contact identifier |
POST | https://your-xconnect-url.com/odata/contacts({you-contact-id})/your-facet | Insert new data for the specific facet for a given contact identified by their contact identifier |
GET | https://your-xconnect-url.com/odata/interactions | Retrieves a list of all interactions in xConnect |
POST | https://your-xconnect-url.com/odata/contacts({your-contact-id})/interactions | Insert a new interaction in xConnect for a given contact identified by their contact identifier |
Section 3: Docker
Docker is one of the new features of Sitecore XP 10. Docker is a powerful tool for managing containers and simplifying the deployment process for Sitecore XP. You can easily build, run, and manage Docker containers for your Sitecore sites, without the need for complex command-line syntax.
Some of the most useful Docker commands include building Docker images, running Docker containers, and connecting to the Sitecore instance running inside a Docker container. s needed for your specific site configuration.
Command | Description |
---|---|
docker build | Build a Docker image from a Dockerfile |
docker help | List all available commands |
docker container | Manages Docker containers, including starting, stopping, and removing them. |
docker exec | Execute a command inside a running Docker container |
docker images | Lists all the Docker images on the local machine. |
docker info | Display high-level information for your Docker environment (version, root directory, default isolation mode, and so on) |
docker inspect <image> | Returns low-level information of the image |
docker network | Manages Docker networks, including creating and removing them. |
docker ps | List running Docker containers |
docker pull | Downloads the latest version of a Sitecore Docker image from Docker Hub. |
docker rm | Remove a Docker container |
docker run | Start a new Docker container |
docker start <container> | Starts a stopped Docker container. |
docker stop <container> | Stop a running Docker container |
docker system prune | Removes all stopped containers, dangling images, and unused networks and volumes. |
docker volume | Manages Docker volumes, including creating and removing them. |
docker-compose build | Builds a new Docker image from the specified docker-compose.yml file. |
docker-compose down | Stops and removes the Docker containers specified in the docker-compose.yml file. |
docker-compose down –volumes | Stops and removes Docker containers, networks, and volumes created by docker-compose up. |
docker-compose exec | Runs a command inside a running Docker container. |
docker-compose logs | Displays the logs of the running Docker containers. |
docker-compose ps | Lists the running containers defined in the docker-compose.yml file. |
docker-compose restart | Restarts Docker containers. |
docker-compose run | Runs a one-time command against a service. |
docker-compose start | Starts stopped Docker containers. |
docker-compose stop | Stops running Docker containers. |
docker-compose up | Starts the Docker containers specified in the docker-compose.yml file. |
docker-compose.yml | The main configuration file used by the docker-compose command. It contains information about the different containers (referred to as services) and their configuration. |
.env | This is an environment file. The values here provide default values for any environment variables referenced in the Compose file, or you use it to configure Compose. |
.\Clean.ps1 | Clean the data of the Sitecore Docker instance |
.\Init.ps1 | Initialize and prepare the environment for running a Sitecore Docker instance |
.\Start.ps1 | Build and initialize Sitecore Docker images |
.\Stop.ps1 | Stop a Sitecore Docker instance |
Section 4: Sitecore CLI
Sitecore CLI is a command-line tool for managing Sitecore XP installations, making it easier to automate common tasks and streamline your development workflow. You can quickly access the most frequently used Sitecore CLI commands, allowing you to save time and avoid errors.
Some of the most important Sitecore CLI commands in the Cheat Sheet include installing Sitecore, deploying Sitecore, and managing Sitecore packages.
sitecore index | Automates indexing operations. Install the indexing plugin to access this command. |
sitecore init | Initializes a project configuration in the current folder. |
sitecore itemres | Creates an item package in a resource file with configurable options. Install the Items as Resources plugin to access this command. |
sitecore login | Logs in to a Sitecore instance. |
sitecore plugin | Manages plugins for the CLI that contain additional commands.. |
sitecore publish | Publishes all content from the Master database to the Web database. Install the publishing plugin to access this command. |
sitecore ser, serialization | Handles the serialization of items. Install the serialization plugin to access this command. |
sitecore connect | Connect your environment to a different existing environment and use its login information. |
sitecore edge | Helps you manage Experience Edge API keys. |
sitecore dbcleanup | Performs database cleanup according to the provided tasks. |
In summary…
Having a Cheat Sheet can be a major time-saver and productivity booster for any developer. With quick access to the most frequently used commands for rendering, xConnect, Docker, and Sitecore CLI, you can spend less time searching for the correct syntax and more time building great websites. Whether you’re a seasoned Sitecore developer or just getting started, a Cheat Sheet can be an invaluable tool for streamlining your workflow and making your development process more efficient.
Find a typo or something wrong? Would you like to improve this Cheat Sheet? Get in touch with me!
Leave a Reply