================ CODE SNIPPETS ================ TITLE: Complete Program.cs Example - .NET 6+ DESCRIPTION: Shows a complete example of the Program.cs file for a .NET 6+ application configured to use Orchard Core CMS. It includes building the web application, adding Orchard Core services, configuring static files, and adding the Orchard Core middleware. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/getting-started/README.md#_snippet_4 LANGUAGE: C# CODE: ``` var builder = WebApplication.CreateBuilder(args); builder.Services.AddOrchardCms(); var app = builder.Build(); if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseStaticFiles(); app.UseOrchardCore(); app.Run(); ``` -------------------------------- TITLE: Installing Start Bootstrap Coming Soon Theme DESCRIPTION: These commands demonstrate how to install the Start Bootstrap Coming Soon theme template files using either the npm package manager or by cloning the project repository from GitHub. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheComingSoonTheme/Assets/TheComingSoonTheme/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` npm i startbootstrap-coming-soon ``` LANGUAGE: Shell CODE: ``` git clone https://github.com/StartBootstrap/startbootstrap-coming-soon.git ``` -------------------------------- TITLE: Installing Theme via npm Shell DESCRIPTION: Installs the Start Bootstrap Clean Blog theme package using the npm package manager. This command fetches the theme files from the npm registry and adds them to your project's dependencies. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheBlogTheme/Assets/TheBlogTheme/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` npm i startbootstrap-clean-blog ``` -------------------------------- TITLE: Using Start Bootstrap Coming Soon Theme Build Scripts DESCRIPTION: These npm commands are used in the advanced development workflow. They install dependencies, build the project assets, compile source files (Pug, SCSS, JS), clean the build directory, and start a local development server with live reloading. Requires Node.js and npm installed. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheComingSoonTheme/Assets/TheComingSoonTheme/README.md#_snippet_1 LANGUAGE: Shell CODE: ``` npm install ``` LANGUAGE: Shell CODE: ``` npm start ``` LANGUAGE: Shell CODE: ``` npm run build ``` LANGUAGE: Shell CODE: ``` npm run build:assets ``` LANGUAGE: Shell CODE: ``` npm run build:pug ``` LANGUAGE: Shell CODE: ``` npm run build:scripts ``` LANGUAGE: Shell CODE: ``` npm run build:scss ``` LANGUAGE: Shell CODE: ``` npm run clean ``` LANGUAGE: Shell CODE: ``` npm run start:debug ``` -------------------------------- TITLE: Installing Start Bootstrap Agency Theme (npm) DESCRIPTION: Describes how to install the Agency theme as a package using the npm package manager. This command downloads the theme package and its dependencies into your project's node_modules directory. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheAgencyTheme/Assets/TheAgencyTheme/README.md#_snippet_0 LANGUAGE: bash CODE: ``` npm i startbootstrap-agency ``` -------------------------------- TITLE: Installing Project Dependencies (npm) DESCRIPTION: Instructs the user to install the necessary project dependencies after cloning the theme's source code. Running this command in the theme's root directory will install packages listed in the package.json file. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheAgencyTheme/Assets/TheAgencyTheme/README.md#_snippet_2 LANGUAGE: bash CODE: ``` npm install ``` -------------------------------- TITLE: Installing Project Dependencies via npm Shell DESCRIPTION: Executes `npm install` in the theme's root directory after cloning the repository. This command reads the `package.json` file and downloads all necessary project dependencies, such as build tools and libraries. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheBlogTheme/Assets/TheBlogTheme/README.md#_snippet_2 LANGUAGE: Shell CODE: ``` npm install ``` -------------------------------- TITLE: Starting Development Server (npm) DESCRIPTION: Explains how to start the local development server provided by the theme's build environment using `npm start` (or `npm run start`). This command typically builds assets, launches a live preview in your browser, and watches for changes for live reloading. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheAgencyTheme/Assets/TheAgencyTheme/README.md#_snippet_3 LANGUAGE: bash CODE: ``` npm start ``` -------------------------------- TITLE: Minimal OrchardCore Program.cs Setup (C#) DESCRIPTION: Provides a simplified example of the Program.cs file after integrating Orchard Core CMS. It shows the basic structure including creating the WebApplication builder, adding Orchard Core services, configuring essential middleware like UseStaticFiles() and UseOrchardCore(), and finally running the application, representing a minimal setup for a decoupled CMS. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/decoupled-cms/README.md#_snippet_4 LANGUAGE: C# CODE: ``` public class Program { public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddOrchardCms(); var app = builder.Build(); app.UseStaticFiles(); app.UseOrchardCore(); app.Run(); } } ``` -------------------------------- TITLE: Hosting Orchard Core Server (Bash) DESCRIPTION: Starts the Orchard Core server instance that the end-to-end tests will run against. This command is required to make the application available and accessible for testing by Cypress. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/test/OrchardCore.Tests.Functional/Readme.md#_snippet_6 LANGUAGE: bash CODE: ``` npm run cms:host ``` -------------------------------- TITLE: Configuring Auto Setup Parameters - JSON DESCRIPTION: This JSON snippet shows an example configuration for the OrchardCore_AutoSetup section within appsettings.json. It defines the optional AutoSetupPath and an array of Tenants, where each object specifies settings required for the automatic setup of a single tenant, including site details, admin credentials, database connection info, recipe to use, and URL prefixes. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/AutoSetup/README.md#_snippet_0 LANGUAGE: json CODE: ``` "OrchardCore": { "OrchardCore_AutoSetup": { "AutoSetupPath": "", "Tenants": [ { "ShellName": "Default", "SiteName": "AutoSetup Example", "SiteTimeZone": "Europe/Amsterdam", "AdminUsername": "admin", "AdminEmail": "info@orchardproject.net", "AdminPassword": "OrchardCoreRules1!", "DatabaseProvider": "Sqlite", "DatabaseConnectionString": "", "DatabaseTablePrefix": "", "RecipeName": "SaaS" }, { "ShellName": "AutoSetupTenant", "SiteName": "AutoSetup Tenant", "SiteTimeZone": "Europe/Amsterdam", "AdminUsername": "tenantadmin", "AdminEmail": "tenant@orchardproject.net", "AdminPassword": "OrchardCoreRules1!", "DatabaseProvider": "Sqlite", "DatabaseConnectionString": "", "DatabaseTablePrefix": "tenant", "RecipeName": "Agency", "RequestUrlHost": "", "RequestUrlPrefix": "tenant", "FeatureProfile": "my-profile" } ] } } ``` -------------------------------- TITLE: Starting Development Server (Alias) via npm Shell DESCRIPTION: Another way to run the `start` script (`npm start`), which runs the project for development, launches a live preview, and watches for file changes. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheBlogTheme/Assets/TheBlogTheme/README.md#_snippet_12 LANGUAGE: Shell CODE: ``` npm run start ``` -------------------------------- TITLE: Installing Node.js Dependencies (Bash) DESCRIPTION: Installs all required Node.js packages listed in the `package.json` file. This is the first step after cloning the repository to set up the testing environment for Cypress. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/test/OrchardCore.Tests.Functional/Readme.md#_snippet_0 LANGUAGE: bash CODE: ``` npm install ``` -------------------------------- TITLE: Starting Development Server via npm Shell DESCRIPTION: Runs the `start` script defined in the theme's `package.json` file. This typically launches a local development server, opens a preview in the browser, and sets up live reloading for development. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheBlogTheme/Assets/TheBlogTheme/README.md#_snippet_3 LANGUAGE: Shell CODE: ``` npm start ``` -------------------------------- TITLE: Example Recipe Custom Configuration DESCRIPTION: This JSON snippet illustrates how custom configuration keys, such as `CustomConfigurationKey`, can be included within a recipe's configuration section. These keys are then accessible within recipe steps using the `configuration()` JavaScript function. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/Setup/README.md#_snippet_0 LANGUAGE: json CODE: ``` { "ConnectionString": "...", "DatabaseProvider": "Sqlite", "TablePrefix": "Test", "CustomConfigurationKey": "Custom Configuration Value" } ``` -------------------------------- TITLE: Starting Project in Debug Mode (npm) DESCRIPTION: Explains how to run the project using a specific debug configuration defined by the `start:debug` script in `package.json`. This mode likely provides additional logging or debugging features compared to the standard `npm start`. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheAgencyTheme/Assets/TheAgencyTheme/README.md#_snippet_10 LANGUAGE: bash CODE: ``` npm run start:debug ``` -------------------------------- TITLE: Serving MkDocs Site Locally - Shell DESCRIPTION: Starts the MkDocs local development server, making the documentation site accessible in a web browser, typically at http://127.0.0.1:8000. This allows contributors to preview their changes in a live environment before submitting. Requires MkDocs and documentation dependencies to be installed. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/contributing/contributing-documentation.md#_snippet_3 LANGUAGE: Shell CODE: ``` python -m mkdocs serve ``` -------------------------------- TITLE: Adding Orchard Core CMS Services - Program.cs DESCRIPTION: Registers the necessary Orchard Core CMS services with the dependency injection container using the AddOrchardCms() extension method on IServiceCollection within the Program.cs file. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/getting-started/README.md#_snippet_5 LANGUAGE: C# CODE: ``` builder.Services.AddOrchardCms(); ``` -------------------------------- TITLE: Starting Project in Debug Mode via npm Shell DESCRIPTION: Runs the `start:debug` script as defined in `package.json`, which launches the project potentially with debugging features enabled. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheBlogTheme/Assets/TheBlogTheme/README.md#_snippet_11 LANGUAGE: Shell CODE: ``` npm run start:debug ``` -------------------------------- TITLE: Default Setup Culture Configuration DESCRIPTION: This JSON snippet demonstrates the default configuration structure for the `OrchardCore_Setup` module. It allows defining the `DefaultCulture` for the setup screen (using `""` to use the OS culture) and listing the `SupportedCultures` available during setup. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/Setup/README.md#_snippet_2 LANGUAGE: json CODE: ``` { "OrchardCore_Setup": { "DefaultCulture": "", "SupportedCultures": [ "ar", "cs", "da", "de", "el", "en", "es", "fa", "fi", "fr", "he", "hr", "hu", "id", "it", "ja", "ko", "lt", "mk", "nl", "pl", "pt", "ru", "sk", "sl", "sr-cyrl-rs", "sr-latn-rs", "sv", "tr", "uk", "vi", "zh-CN", "zh-TW" ] } } ``` -------------------------------- TITLE: Adding Orchard Core Middleware to Pipeline - Program.cs DESCRIPTION: Adds the core Orchard Core middleware to the application's request pipeline using the UseOrchardCore() extension method on IApplicationBuilder, enabling Orchard Core to handle requests instead of the default endpoint. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/getting-started/README.md#_snippet_7 LANGUAGE: C# CODE: ``` app.UseOrchardCore(); ``` -------------------------------- TITLE: Example AppSettings Admin URL Prefix Configuration DESCRIPTION: This JSON snippet shows how a configuration key like `OrchardCore_Admin:AdminUrlPrefix` can be defined in a host's `appsettings.json` or similar configuration source. This key's value can then be retrieved within a recipe using `configuration('OrchardCore_Admin:AdminUrlPrefix', 'Admin')`, demonstrating the use of a default value. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/Setup/README.md#_snippet_1 LANGUAGE: json CODE: ``` { "OrchardCore_Admin" : { "AdminUrlPrefix" : "MyAdmin" } } ``` -------------------------------- TITLE: Adding Orchard Core Middleware to Pipeline - .NET 6+ DESCRIPTION: Adds the core Orchard Core middleware to the application's request pipeline using the UseOrchardCore() extension method on IApplicationBuilder. This enables Orchard Core to handle incoming requests and render pages. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/getting-started/README.md#_snippet_3 LANGUAGE: C# CODE: ``` app.UseOrchardCore(); ``` -------------------------------- TITLE: Installing MkDocs with PIP - Shell DESCRIPTION: Installs the MkDocs static site generator globally using the Python package installer, PIP. This is a prerequisite for running the documentation site locally. Requires Python and PIP to be installed. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/contributing/contributing-documentation.md#_snippet_1 LANGUAGE: Shell CODE: ``` pip install mkdocs ``` -------------------------------- TITLE: Enabling OrchardCore Auto Setup Feature (C#) DESCRIPTION: C# code snippet for the `ConfigureServices` method in the project's `Startup.cs` file. It demonstrates how to enable the `OrchardCore.AutoSetup` feature by adding it to the Orchard CMS services configuration using the `AddSetupFeatures` extension method. This integrates the auto setup functionality into the application startup process. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/AutoSetup/README.md#_snippet_2 LANGUAGE: csharp CODE: ``` public void ConfigureServices(IServiceCollection services) { services .AddOrchardCms() .AddSetupFeatures("OrchardCore.AutoSetup"); } ``` -------------------------------- TITLE: Building Project for Distribution via npm Shell DESCRIPTION: Executes the main `build` script, which processes and compiles all source files (Pug, SCSS, JS, assets) into the `dist` directory, preparing the project for deployment or distribution. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheBlogTheme/Assets/TheBlogTheme/README.md#_snippet_5 LANGUAGE: Shell CODE: ``` npm run build ``` -------------------------------- TITLE: Adding Orchard Core CMS Services - .NET 6+ DESCRIPTION: Registers the necessary Orchard Core CMS services with the dependency injection container using the AddOrchardCms() extension method on IServiceCollection. This is required to enable Orchard Core functionality. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/getting-started/README.md#_snippet_1 LANGUAGE: C# CODE: ``` builder.Services.AddOrchardCms(); ``` -------------------------------- TITLE: Building Project Assets via npm Shell DESCRIPTION: Runs the `build:assets` script to copy files from the `src/assets/` directory to the output `dist` directory. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheBlogTheme/Assets/TheBlogTheme/README.md#_snippet_6 LANGUAGE: Shell CODE: ``` npm run build:assets ``` -------------------------------- TITLE: Cloning Start Bootstrap Agency Theme Repository (Git) DESCRIPTION: Explains how to clone the theme's source code repository from GitHub using the Git command-line tool. Cloning is necessary if you plan to use the theme's build environment and advanced features. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheAgencyTheme/Assets/TheAgencyTheme/README.md#_snippet_1 LANGUAGE: bash CODE: ``` git clone https://github.com/StartBootstrap/startbootstrap-agency.git ``` -------------------------------- TITLE: Building Project Assets (npm) DESCRIPTION: Describes how to run the full build process for the theme using npm scripts. This command executes the necessary steps to compile and copy all source files (assets, Pug, JS, SCSS) into the `dist` directory, preparing the theme for production. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheAgencyTheme/Assets/TheAgencyTheme/README.md#_snippet_4 LANGUAGE: bash CODE: ``` npm run build ``` -------------------------------- TITLE: Enabling Distributed Lock and Auto Setup (C#) DESCRIPTION: C# code snippet for the `ConfigureServices` method in the project's `Startup.cs`. It shows how to enable both the `OrchardCore.Redis.Lock` and `OrchardCore.AutoSetup` features. This setup is necessary when multiple OrchardCore instances share the same database and require a distributed lock mechanism (like Redis) to ensure atomic auto setup. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/AutoSetup/README.md#_snippet_3 LANGUAGE: csharp CODE: ``` public void ConfigureServices(IServiceCollection services) { services .AddOrchardCms() .AddSetupFeatures("OrchardCore.Redis.Lock", "OrchardCore.AutoSetup"); } ``` -------------------------------- TITLE: Building Project Styles via npm Shell DESCRIPTION: Runs the `build:scss` script to compile SCSS style files from `src/scss/` into CSS files within the `dist` directory. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheBlogTheme/Assets/TheBlogTheme/README.md#_snippet_9 LANGUAGE: Shell CODE: ``` npm run build:scss ``` -------------------------------- TITLE: Installing Orchard Core Project Templates (Shell) DESCRIPTION: This command installs the official Orchard Core project templates using the .NET `new install` command. It targets a specific version (`2.1.7-*`) to ensure compatibility. This template is required to generate Orchard Core projects. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/create-cms-application/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` dotnet new install OrchardCore.ProjectTemplates::2.1.7-* ``` -------------------------------- TITLE: Building Project Scripts via npm Shell DESCRIPTION: Runs the `build:scripts` script, which typically copies or processes the main JavaScript file (`src/js/scripts.js`) into the `dist` directory. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheBlogTheme/Assets/TheBlogTheme/README.md#_snippet_8 LANGUAGE: Shell CODE: ``` npm run build:scripts ``` -------------------------------- TITLE: Cloning Theme Repository via Git Shell DESCRIPTION: Clones the official GitHub repository for the Start Bootstrap Clean Blog theme using the Git command-line tool. This method is used to obtain the theme's source files for advanced usage and development. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheBlogTheme/Assets/TheBlogTheme/README.md#_snippet_1 LANGUAGE: Shell CODE: ``` git clone https://github.com/StartBootstrap/startbootstrap-clean-blog.git ``` -------------------------------- TITLE: Compiling Pug Templates via npm Shell DESCRIPTION: Runs the `build:pug` script to compile Pug template files located in `src/pug/` into HTML files within the `dist` directory. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheBlogTheme/Assets/TheBlogTheme/README.md#_snippet_7 LANGUAGE: Shell CODE: ``` npm run build:pug ``` -------------------------------- TITLE: Removing Default Endpoint - Program.cs DESCRIPTION: Removes or replaces the default MapGet endpoint configuration from the application's request pipeline in the Program.cs file, as Orchard Core will handle routing and endpoints. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/getting-started/README.md#_snippet_6 LANGUAGE: C# CODE: ``` app.MapGet("/", () => "Hello World!"); ``` -------------------------------- TITLE: Install Preview Orchard Core Project Templates (CMD) DESCRIPTION: This command installs the latest preview version of the Orchard Core Project Templates from a specific NuGet feed. It is used to access development or unstable versions of the templates before they are officially released. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/getting-started/templates/README.md#_snippet_1 LANGUAGE: CMD CODE: ``` dotnet new install OrchardCore.ProjectTemplates::2.1.7-* --nuget-source https://nuget.cloudsmith.io/orchardcore/preview/v3/index.json ``` -------------------------------- TITLE: Install Stable Orchard Core Project Templates (CMD) DESCRIPTION: This command uses the `dotnet new` tool to install the specified version of the official Orchard Core Project Templates NuGet package. This allows users to create new Orchard Core projects directly from the command line using predefined templates. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/getting-started/templates/README.md#_snippet_0 LANGUAGE: CMD CODE: ``` dotnet new install OrchardCore.ProjectTemplates::2.1.7 ``` -------------------------------- TITLE: Building and Starting Docker Compose Services with Pruning - CMD DESCRIPTION: Provides command-line instructions to build Docker images defined in `docker-compose.yml`, prune intermediate images specifically tagged `stage=build-env`, and then start all defined services (web and databases) using `docker-compose up`. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/topics/docker/README.md#_snippet_5 LANGUAGE: cmd CODE: ``` REM Builds images if they are not already built docker-compose build REM Prune intermediate remaining images docker image prune -f --filter label=stage=build-env REM Start all containers docker-compose up ``` -------------------------------- TITLE: Removing Default Razor Pages Service - .NET 6+ DESCRIPTION: Removes the default AddRazorPages() service registration from the IServiceCollection in the Program.cs file when using .NET 6 or later, as Orchard Core handles view rendering. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/getting-started/README.md#_snippet_0 LANGUAGE: C# CODE: ``` builder.Services.AddRazorPages(); ``` -------------------------------- TITLE: Installing Node.js and Yarn Dependencies (CMD) DESCRIPTION: Commands to install Node.js prerequisites and Yarn v4.6.x using corepack from the root of the repository. This prepares the environment for running asset management commands. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/assets-manager/README.md#_snippet_0 LANGUAGE: cmd CODE: ``` REM On Windows may require to run command shell with administrator privileges. corepack enable yarn ``` -------------------------------- TITLE: Installing Orchard Core Project Templates (.NET CLI) DESCRIPTION: Installs the specified stable release of the Orchard Core project templates globally using the .NET CLI's `dotnet new install` command. These templates provide shortcuts for creating Orchard Core web applications and modules. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/create-modular-application-mvc/README.md#_snippet_0 LANGUAGE: .NET CLI CODE: ``` dotnet new install OrchardCore.ProjectTemplates::2.1.7-* ``` -------------------------------- TITLE: Removing Default Middleware - .NET 6+ DESCRIPTION: Removes default middleware registrations like UseHttpsRedirection, UseRouting, UseAuthorization, and MapRazorPages from the application's request pipeline in the Program.cs file. These are typically replaced or handled differently by Orchard Core. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/getting-started/README.md#_snippet_2 LANGUAGE: C# CODE: ``` app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.MapRazorPages(); ``` -------------------------------- TITLE: Installing NPM Packages DESCRIPTION: This command is used to install all necessary Node.js packages, including Gulp and its dependencies, as listed in the `package.json` file. It must be executed from the Orchard Core solution folder. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/gulp-pipeline/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` npm install ``` -------------------------------- TITLE: Installing Docs Dependencies with PIP - Shell DESCRIPTION: Installs the specific Python dependencies required for the Orchard Core documentation site using PIP and the `requirements.txt` file located in the documentation source directory. This ensures all necessary MkDocs plugins and themes are available. Requires Python, PIP, and the cloned repository. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/contributing/contributing-documentation.md#_snippet_2 LANGUAGE: Shell CODE: ``` pip install -r src/docs/requirements.txt ``` -------------------------------- TITLE: Building Project Scripts (npm) DESCRIPTION: Explains the npm script responsible for processing and copying the main JavaScript file (`src/js/scripts.js`) to the `dist` directory. This command handles the theme's primary JavaScript logic as part of the build. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheAgencyTheme/Assets/TheAgencyTheme/README.md#_snippet_7 LANGUAGE: bash CODE: ``` npm run build:scripts ``` -------------------------------- TITLE: Install OrchardCore PoExtractor Tool - Bash DESCRIPTION: Provides the command-line instruction using the .NET CLI to install the OrchardCoreContrib.PoExtractor tool globally on the system. This tool is used to extract translatable strings from OrchardCore projects. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/Localize/README.md#_snippet_7 LANGUAGE: bash CODE: ``` dotnet tool install --global OrchardCoreContrib.PoExtractor ``` -------------------------------- TITLE: Generating Blog Sample Data (Bash) DESCRIPTION: Executes a script to generate sample data specifically for the blog recipe within Orchard Core. This is useful for testing blog-related features that require pre-existing content in the database. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/test/OrchardCore.Tests.Functional/Readme.md#_snippet_7 LANGUAGE: bash CODE: ``` npm run gen:blog ``` -------------------------------- TITLE: Cleaning Build Directory via npm Shell DESCRIPTION: Executes the `clean` script to delete the entire `dist` directory, often done before a fresh build to ensure a clean output. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheBlogTheme/Assets/TheBlogTheme/README.md#_snippet_10 LANGUAGE: Shell CODE: ``` npm run clean ``` -------------------------------- TITLE: Cleaning Build Directory (npm) DESCRIPTION: Describes the npm script that removes the `dist` directory, effectively cleaning up previously built files. Running this command is often a prerequisite before performing a fresh build of the project. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheAgencyTheme/Assets/TheAgencyTheme/README.md#_snippet_9 LANGUAGE: bash CODE: ``` npm run clean ``` -------------------------------- TITLE: Executing Database Queries & Transactions - C# DESCRIPTION: Provides an example `AdminController` demonstrating how to interact with the database in Orchard Core using `IDbConnectionAccessor`, `IStore`, and `ShellSettings`. It shows how to obtain a connection, get the SQL dialect for provider-agnostic queries, handle tenant table prefixes, and execute queries or commands with Dapper, including performing operations within an explicit database transaction. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/Data/README.md#_snippet_4 LANGUAGE: csharp CODE: ``` using Dapper; using OrchardCore.Data; using OrchardCore.Environment.Shell; using YesSql; public sealed class AdminController : Controller { private readonly IDbConnectionAccessor _dbAccessor; private readonly IStore _store; private readonly string _tablePrefix; public AdminController(IDbConnectionAccessor dbAccessor, IStore store, ShellSettings settings) { _dbAccessor = dbAccessor; _store = store; _tablePrefix = settings["TablePrefix"]; } public async Task Query() { await using (var connection = _dbAccessor.CreateConnection()) { var dialect = _store.Configuration.SqlDialect; var customTable = dialect.QuoteForTableName($"{_tablePrefix}CustomTable"); var model = await connection.QueryAsync($"SELECT * FROM {customTable};"); return View(model); } } public async Task DeleteUsingTransaction() { await using (var connection = _dbAccessor.CreateConnection()) { using (var transaction = await connection.BeginTransactionAsync()) { try { var dialect = _store.Configuration.SqlDialect; var customTable1 = dialect.QuoteForTableName($"{_tablePrefix}CustomTable1"); var customTable2 = dialect.QuoteForTableName($"{_tablePrefix}CustomTable2"); var command1 = $"DELETE FROM {customTable1};"; var command2 = $"DELETE FROM {customTable2};"; await connection.ExecuteAsync(command1); await connection.ExecuteAsync(command2); await transaction.CommitAsync(); } catch { // If an exception occurs the transaction is rollbacked await transaction.RollbackAsync(); } return Content("Done!"); } } } public async Task DeleteNoTransaction() { await using (var connection = _dbAccessor.CreateConnection()) { var dialect = _store.Configuration.SqlDialect; var customTable1 = dialect.QuoteForTableName($"{_tablePrefix}CustomTable1"); var customTable2 = dialect.QuoteForTableName($"{_tablePrefix}CustomTable2"); var command = $"DELETE FROM {customTable1}; DELETE FROM {customTable2};"; await connection.ExecuteAsync(command); return Content("Done!"); } } } ``` -------------------------------- TITLE: Compiling Pug Files (npm) DESCRIPTION: Describes the npm script used to compile Pug template files located in the `src/pug/` directory into static HTML files within the `dist` directory. This is a specific step within the overall build process. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheAgencyTheme/Assets/TheAgencyTheme/README.md#_snippet_6 LANGUAGE: bash CODE: ``` npm run build:pug ``` -------------------------------- TITLE: Creating Orchard Core CMS Project using dotnet new - Shell DESCRIPTION: Provides a sequence of command-line steps to create a new .NET solution directory, initialize a solution file, create an Orchard Core CMS project using the 'occms' template, and add the project to the solution. This is a standard way to set up an Orchard Core application from the command line. Requires the .NET SDK and the Orchard Core code generation templates to be installed globally or locally. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/create-blazor-cms/README.md#_snippet_0 LANGUAGE: shell CODE: ``` mkdir OCBlazor cd OCBlazor dotnet new sln dotnet new occms -o BlazorCms dotnet sln add ./BlazorCms ``` -------------------------------- TITLE: Install Orchard Core Project Templates - .NET CLI DESCRIPTION: Installs the specified version of Orchard Core project templates globally using the .NET CLI. These templates are required to easily create Orchard Core sites and modules. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/add-admin-menu/README.md#_snippet_0 LANGUAGE: shell CODE: ``` dotnet new install OrchardCore.ProjectTemplates::2.1.7-* ``` -------------------------------- TITLE: Building Project Assets Only (npm) DESCRIPTION: Details how to run a specific build script to copy only the static asset files from the `src/assets/` directory to the `dist` directory. This is a partial build command focused solely on assets. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheAgencyTheme/Assets/TheAgencyTheme/README.md#_snippet_5 LANGUAGE: bash CODE: ``` npm run build:assets ``` -------------------------------- TITLE: Setting OrchardCore Auto Setup User Secrets (Shell) DESCRIPTION: Provides shell commands using the `dotnet user-secrets` tool to initialize user secrets and set various configuration values for the OrchardCore Auto Setup feature. These secrets are stored locally and used during development to avoid committing sensitive information to the repository. Requires the .NET CLI and the OrchardCore.Cms.Web project context. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/AutoSetup/README.md#_snippet_1 LANGUAGE: shell CODE: ``` cd src/OrchardCore.Cms.Web dotnet user-secrets init dotnet user-secrets set "OrchardCore:OrchardCore_AutoSetup:Tenants:0:ShellName" "Default" dotnet user-secrets set "OrchardCore:OrchardCore_AutoSetup:Tenants:0:SiteName" "AutoSetup Example" dotnet user-secrets set "OrchardCore:OrchardCore_AutoSetup:Tenants:0:SiteTimeZone" "Europe/Amsterdam" dotnet user-secrets set "OrchardCore:OrchardCore_AutoSetup:Tenants:0:AdminUsername" "admin" dotnet user-secrets set "OrchardCore:OrchardCore_AutoSetup:Tenants:0:AdminEmail" "info@orchardproject.net" dotnet user-secrets set "OrchardCore:OrchardCore_AutoSetup:Tenants:0:AdminPassword" "OrchardCoreRules1!" dotnet user-secrets set "OrchardCore:OrchardCore_AutoSetup:Tenants:0:RecipeName" "SaaS" dotnet user-secrets set "OrchardCore:OrchardCore_AutoSetup:Tenants:0:DatabaseProvider" "Sqlite" ``` -------------------------------- TITLE: Managing Node.js Versions with NVM DESCRIPTION: These commands use Node Version Manager (NVM) to install or switch to a specific version of Node.js, specifically targeting version 18 in this example. This can be helpful if Gulp tasks fail on the current Node.js version. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/gulp-pipeline/README.md#_snippet_2 LANGUAGE: Shell CODE: ``` nvm install 18 ``` LANGUAGE: Shell CODE: ``` nvm use 18 ``` -------------------------------- TITLE: Example Tokenized Media URL (HTML) DESCRIPTION: Provides an example of a media URL generated by OrchardCore when UseTokenizedQueryString is enabled. It shows the base path, image name, requested dimensions (width/height), and the HMAC signature token parameter used to validate the request and prevent denial-of-service attacks. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/Media/README.md#_snippet_9 LANGUAGE: HTML CODE: ``` ``` -------------------------------- TITLE: Building Orchard Core Environment (Bash) DESCRIPTION: Builds or rebuilds the necessary Orchard Core environment required for running the end-to-end tests. This step might involve compiling, packaging, or setting up application dependencies before testing. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/test/OrchardCore.Tests.Functional/Readme.md#_snippet_5 LANGUAGE: bash CODE: ``` npm run cms:build ``` -------------------------------- TITLE: Configuring Comprehensive Placement Rule with Filters (OrchardCore JSON) DESCRIPTION: Provides a complete example of a placement rule in placement.json, demonstrating various filter options (displayType, differentiator, contentType, contentPart, path) and placement attributes (place, alternates, wrappers, shape). SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/Placement/README.md#_snippet_2 LANGUAGE: JSON CODE: ``` { "TextField": [ { "displayType": "Detail", "differentiator": "Article-MyTextField", "contentType": [ "Page", "BlogPost" ], "contentPart": [ "HtmlBodyPart" ], "path": [ "/mypage" ], "place": "Content", "alternates": [ "TextField_Title" ], "wrappers": [ "TextField_Title" ], "shape": "AnotherShape" } ] } ``` -------------------------------- TITLE: Registering Custom Deployment Step (New) - C# DESCRIPTION: Demonstrates the new, simplified approach to registering a custom deployment step using the AddDeployment<> extension in Orchard Core 2.0. This ensures proper serialization with System.Text.Json and replaces the previous multi-step registration. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/releases/2.0.0.md#_snippet_1 LANGUAGE: C# CODE: ``` services.AddDeployment(); ``` -------------------------------- TITLE: Running Orchard Core CMS Project (Shell) DESCRIPTION: This command executes the compiled Orchard Core application located at the specified project file path (`.\MySite\MySite.csproj`). It starts the web server and makes the application accessible via the configured ports, typically 5000 (HTTP) and 5001 (HTTPS). SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/create-cms-application/README.md#_snippet_2 LANGUAGE: Shell CODE: ``` dotnet run --project .\MySite\MySite.csproj ``` -------------------------------- TITLE: Example Orchard Core Theme Manifest.cs (C#) DESCRIPTION: This C# code defines the `Manifest.cs` file for an Orchard Core theme. It uses the `[Theme]` attribute to provide metadata like the theme's name, author, website, version, and description, allowing Orchard Core to identify and list the theme. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/getting-started/templates/README.md#_snippet_12 LANGUAGE: C# CODE: ``` using OrchardCore.DisplayManagement.Manifest; [assembly: Theme( Name = "TemplateTheme.OrchardCore", Author = "The Orchard Team", Website = "https://orchardproject.net", Version = "0.0.1", Description = "The TemplateTheme." )] ``` -------------------------------- TITLE: Retrieving Site Settings Manually in Orchard Core C# (Old Way) DESCRIPTION: This snippet demonstrates the previous method for retrieving specific site settings. It required first getting the overall site settings object using GetSiteSettingsAsync() and then casting it to the desired settings type using the As() extension method. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/releases/2.0.0.md#_snippet_27 LANGUAGE: csharp CODE: ``` (await _siteService.GetSiteSettingsAsync()).As(); ``` -------------------------------- TITLE: Creating Lucene Index Recipe Step - JSON DESCRIPTION: Demonstrates how to define a 'lucene-index' step within an OrchardCore recipe to create a Lucene index during setup. It specifies the analyzer, whether to index the latest version, and which content types to include. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/Lucene/README.md#_snippet_0 LANGUAGE: JSON CODE: ``` { "steps":[ { "name":"lucene-index", "Indices":[ { "Search":{ "AnalyzerName":"standardanalyzer", "IndexLatest":false, "IndexedContentTypes":[ "Article", "BlogPost" ] } } ] } ] } ``` -------------------------------- TITLE: Running MVC E2E Tests (Bash) DESCRIPTION: Executes the automated end-to-end tests focused on the MVC aspects of Orchard Core. Use this command to verify the functionality of the MVC components within the application. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/test/OrchardCore.Tests.Functional/Readme.md#_snippet_2 LANGUAGE: bash CODE: ``` npm run mvc:test ``` -------------------------------- TITLE: Rendering Dynamic Part in Content Summary Template (OrchardCore HTML) DESCRIPTION: Shows an example of rendering a specific zone ('MyGalleryZone') intended to contain a dynamic part using the DisplayAsync helper within an OrchardCore Content Summary template (.cshtml). SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/Placement/README.md#_snippet_9 LANGUAGE: HTML CODE: ``` @await DisplayAsync(Model.MyGalleryZone) ``` -------------------------------- TITLE: Run Orchard Core Site - .NET CLI DESCRIPTION: Executes the specified Orchard Core CMS site project using the .NET CLI. This command starts the web server, making the application accessible via browser. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/add-admin-menu/README.md#_snippet_11 LANGUAGE: shell CODE: ``` dotnet run --project .\MySite\MySite.csproj ``` -------------------------------- TITLE: Example JSON Payload for POST /api/content DESCRIPTION: This JSON object provides an example structure for the request body when creating or updating a content item via the `/api/content` POST endpoint. It includes common content item properties and metadata fields. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/Contents/README.md#_snippet_8 LANGUAGE: JSON CODE: ``` { "contentItem": "string", "id": 0, "contentItemId": "string", "contentItemVersionId": "string", "contentType": "string", "published": true, "latest": true, "modifiedUtc": "2024-03-14T11:40:20.331Z", "publishedUtc": "2024-03-14T11:40:20.331Z", "createdUtc": "2024-03-14T11:40:20.331Z", "owner": "string", "author": "string", "displayText": "string" } ``` -------------------------------- TITLE: Building Custom Cypress Commands (Bash) DESCRIPTION: Navigates to the `./cypress-commands` directory and runs the build script (`npm run build`) to bundle custom Cypress commands used by the Orchard Core tests. This is necessary after modifying command source files to update the distributable version. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/test/OrchardCore.Tests.Functional/Readme.md#_snippet_8 LANGUAGE: bash CODE: ``` cd ./cypress-commands\nnpm run build ``` -------------------------------- TITLE: Running Orchard Core Website Dotnet CLI DESCRIPTION: This command runs the Orchard Core website project using the .NET CLI. It starts the web server, making the application accessible via the configured ports, typically http://localhost:5000 and https://localhost:5001. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/create-admin-theme/README.md#_snippet_2 LANGUAGE: shell CODE: ``` dotnet run --project .\MySite\MySite.csproj ``` -------------------------------- TITLE: Rendering Dynamic Part in Content Detail Template (OrchardCore HTML) DESCRIPTION: Shows an example of rendering a specific zone ('MyGalleryZone') intended to contain a dynamic part using the DisplayAsync helper within an OrchardCore Content Detail template (.cshtml). SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/Placement/README.md#_snippet_7 LANGUAGE: HTML CODE: ``` @await DisplayAsync(Model.MyGalleryZone) ``` -------------------------------- TITLE: Compiling SCSS Styles (npm) DESCRIPTION: Details the npm script used to compile SCSS stylesheet files from the `src/scss/` directory into standard CSS files located in the `dist` directory. This command processes the theme's styling source. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/OrchardCore.Themes/TheAgencyTheme/Assets/TheAgencyTheme/README.md#_snippet_8 LANGUAGE: bash CODE: ``` npm run build:scss ``` -------------------------------- TITLE: Registering Custom Deployment Step (Old) - C# DESCRIPTION: Shows the previous method for registering a custom deployment step using individual service registrations for source, factory, and display driver. This approach is deprecated in Orchard Core 2.0 due to the switch to System.Text.Json and should be replaced with the AddDeployment<> extension. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/releases/2.0.0.md#_snippet_0 LANGUAGE: C# CODE: ``` services.AddTransient(); services.AddSingleton(new DeploymentStepFactory()); services.AddScoped, AdminMenuDeploymentStepDriver>(); ``` -------------------------------- TITLE: Configuring Script Resource Management (C#) DESCRIPTION: Example C# code using ResourceManagementOptionsConfiguration to define a script resource 'admin'. It sets dependencies, specifies URLs for both minified and development versions, and sets a version. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/assets-manager/README.md#_snippet_4 LANGUAGE: csharp CODE: ``` _manifest .DefineScript("admin") .SetDependencies("bootstrap", "admin-main", "theme-manager", "jQuery", "Sortable") .SetUrl("~/TheAdmin/js/theadmin/TheAdmin.min.js", "~/TheAdmin/js/theadmin/TheAdmin.js") .SetVersion("1.0.0"); ``` -------------------------------- TITLE: Example IdentityOptions Configuration (JSON) DESCRIPTION: Provides an example JSON structure intended for an 'appsettings.json' file to configure ASP.NET Core Identity options, specifically the 'Lockout' settings. This structure defines properties like 'AllowedForNewUsers', 'DefaultLockoutTimeSpan', and 'MaxFailedAccessAttempts' that will be bound to the `IdentityOptions` object by the C# code. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/lockout-configuration/README.md#_snippet_3 LANGUAGE: JSON CODE: ``` { "IdentityOptions": { "Lockout": { "AllowedForNewUsers": true, "DefaultLockoutTimeSpan ": "00:05:00", "MaxFailedAccessAttempts ": 5 } } } ``` -------------------------------- TITLE: Running CMS Tests in Cypress UI (Bash) DESCRIPTION: Opens the Cypress interactive test runner with the CMS tests preloaded. This allows developers to watch tests run in a browser, debug, and explore application elements interactively. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/test/OrchardCore.Tests.Functional/Readme.md#_snippet_3 LANGUAGE: bash CODE: ``` npm run cms:cypress ``` -------------------------------- TITLE: Create New Orchard Core CMS Site - .NET CLI DESCRIPTION: Creates a new Orchard Core CMS application project named 'MySite' in a new directory. This command utilizes the previously installed Orchard Core templates. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/add-admin-menu/README.md#_snippet_1 LANGUAGE: shell CODE: ``` dotnet new occms -n MySite ``` -------------------------------- TITLE: Example MSBuild AssemblyAttribute ItemGroup DESCRIPTION: Illustrates the general pattern of using MSBuild's ItemGroup and AssemblyAttribute to define assembly-level attributes, specifically showing how `InternalsVisibleTo` can be configured. This serves as an example of the pattern adopted by Orchard Core's MSBuild targets for defining module/theme/feature attributes. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/leverage-csproj-meta-info/README.md#_snippet_0 LANGUAGE: XML CODE: ``` <_Parameter1>Test.$(MSBuildProjectName) ``` -------------------------------- TITLE: Running MVC Tests in Cypress UI (Bash) DESCRIPTION: Opens the Cypress interactive test runner focused on the MVC tests. Use this command for interactive development and debugging of the MVC-specific end-to-end tests in a visual interface. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/test/OrchardCore.Tests.Functional/Readme.md#_snippet_4 LANGUAGE: bash CODE: ``` npm run mvc:cypress ``` -------------------------------- TITLE: Accessing/Modifying Content Items in Controller (CSharp) DESCRIPTION: Provides an example of an ASP.NET Core controller demonstrating how to retrieve a content item by ID using `IOrchardHelper` (`GetProductAsync`), cast it to a strongly typed part (`Product`), access/modify field values, apply the modified part (`Apply`), update the content item via `IContentManager` (`UpdateAsync`), and validate the changes (`ValidateAsync`). It includes both reading (GET) and updating (POST) operations on a "Product" content item. Requires `OrchardCore.ContentManagement`, `OrchardCore.DisplayManagement.Liquid`, and `Microsoft.AspNetCore.Mvc`. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/ContentTypes/README.md#_snippet_9 LANGUAGE: csharp CODE: ``` public sealed class ProductController : Controller { private readonly IOrchardHelper _orchardHelper; private readonly IContentManager _contentManager; public ProductController(IOrchardHelper orchardHelper, IContentManager contentManager) { _orchardHelper = orchardHelper; _contentManager = contentManager; } [HttpGet("/api/product/{productId}")] public async Task GetProductAsync(string productId) { var product = _orchardHelper.GetContentItemByIdAsync(productId); if (product == null) { return NotFoundObjectResult(); } var productPart = product.As(); // you'll get exceptions if any of these Fields are null // the null-conditional operator (?) should be used for any fields which aren't required return new ObjectResult(new { Image = productPart.Image.Paths.FirstOrDefault(), Price = productPart.Price.Value, }); } [HttpPost("/api/product/{productId}/price/{price}")] public async Task UpdateProductPriceAsync(string productId, int price) { //this call will only fetch published content item, which makes publishing after update redundant var product = _orchardHelper.GetContentItemByIdAsync(productId); if (product == null) { return NotFoundObjectResult(); } var productPart = product.As(); productPart.Price.Value = price; product.Apply(productPart); //apply modified part to a content item await _contentManager.UpdateAsync(product); //update will fire handlers which could alter the content item. //validation will cancel changes if product is not valid. It's fired after update since handlers could change the object. return await _contentManager.ValidateAsync(product); } } ``` -------------------------------- TITLE: Preparing Directories and Running Orchard Core App on RHEL DESCRIPTION: These commands prepare the file system by creating necessary directories (App_Data, wwwroot) and setting permissive permissions (777) on them and the executable. They then execute the Orchard Core web application, binding it to port 80 on all interfaces and enabling static file serving from wwwroot. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/topics/red-hat-ecosystem-catalog-certification/README.md#_snippet_1 LANGUAGE: console CODE: ``` sudo mkdir -m 777 App_Data sudo mkdir -m 777 wwwroot sudo chmod 777 ./OrchardCore.Cms.Web sudo ./OrchardCore.Cms.Web --urls http://*:80 --wwwroot ``` -------------------------------- TITLE: Implementing ModularTenantEvents for Tenant Activation in C# DESCRIPTION: Defines a class `MyStartupTaskService` that inherits from `ModularTenantEvents` to implement `IModularTenantEvents`. This allows custom logic to be executed when a tenant is activated by overriding the `ActivatingAsync` method. The example logs a message using an injected `ILogger` instance. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/run-code-on-startup/README.md#_snippet_0 LANGUAGE: csharp CODE: ``` using System; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using OrchardCore.Modules; public class MyStartupTaskService : ModularTenantEvents { private readonly ILogger _logger; public MyStartupTaskService(ILogger logger) { _logger = logger; } public override Task ActivatingAsync() { _logger.LogInformation("A tenant has been activated."); return Task.CompletedTask; } } ``` -------------------------------- TITLE: Configuring Parcel Action in Assets.json (JSON) DESCRIPTION: Example configuration entry in the Assets.json file to define a Parcel build action. It specifies the entry point JavaScript file, the output destination folder, and optional tags. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/assets-manager/README.md#_snippet_1 LANGUAGE: json CODE: ``` [   {     "action": "parcel",     "name": "module-microsoft-datasource-wrapper",     "source": "Assets/Scripts/datasource-wrapper.js",     "dest": "wwwroot/datasource-wrapper",     "tags":["vue3"]   } ] ``` -------------------------------- TITLE: Run OrchardCore PoExtractor Tool - Bash DESCRIPTION: Shows the basic command-line usage of the installed 'extractpo' tool to generate .po files. It requires specifying the input path (project source) and output path (where .po files will be generated), with optional flags for language and template type. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/Localize/README.md#_snippet_8 LANGUAGE: bash CODE: ``` extractpo [-l|--language {"C#"|"VB"}] [-t|--template {"razor"|"liquid"}] ``` -------------------------------- TITLE: Registering Specific Query Type for Serialization - C# DESCRIPTION: Provides a specific example of how to register a custom type inheriting from Query, such as SqlQuery, using services.AddJsonDerivedTypeInfo<> to ensure proper serialization with System.Text.Json in Orchard Core 2.0. This is needed for query types defined in custom modules. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/releases/2.0.0.md#_snippet_6 LANGUAGE: C# CODE: ``` services.AddJsonDerivedTypeInfo(); ``` -------------------------------- TITLE: Grouping Editor Shapes into Cards (OrchardCore JSON) DESCRIPTION: Example demonstrating how to group editor shapes into cards within the content editor by using the '%' modifier and a group name in the 'place' attribute of a placement rule. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/Placement/README.md#_snippet_5 LANGUAGE: JSON CODE: ``` { "MediaField_Edit" : [ { "place" : "Parts:0%Media;0", "contentType": [ "Article" ] } ], "HtmlField_Edit" : [ { "place": "Parts:0%Content;1", "contentType": [ "Article" ] } ] } ``` -------------------------------- TITLE: Basic GraphQL Query Example (JSON) DESCRIPTION: This JSON snippet shows a basic GraphQL query requesting the `displayText` field from a `blog` type. It demonstrates the structure of a simple query without arguments. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/Apis.GraphQL.Abstractions/README.md#_snippet_0 LANGUAGE: json CODE: ``` { blog { displayText } } ``` -------------------------------- TITLE: Setting Up Default SaaS Tenant Cypress Javascript DESCRIPTION: This Cypress test script sets up the default OrchardCore tenant using the 'SaaS' recipe as a prerequisite for other tests. It visits the root URL, runs the `cy.siteSetup` command with tenant details, logs in using configured credentials, and sets the page size for tenant lists using `cy.setPageSize`. This ensures a clean base state for subsequent tenant-based testing. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/test/OrchardCore.Tests.Functional/cypress-commands/README.md#_snippet_2 LANGUAGE: javascript CODE: ``` /// const sassTenant = { name: "Testing SaaS", setupRecipe: "SaaS", } describe("Default tenant setup using SaaS recipe", function() { it("Setup default tenant", function() { cy.visit("/"); cy.siteSetup(sassTenant); cy.login() // this is required to increase paging in the Tenants list page. Since we will be creating a lot of tenants during out testing. cy.setPageSize(sassTenant, "100"); }); }); ``` -------------------------------- TITLE: Example Orchard Core Module Manifest.cs (C#) DESCRIPTION: This C# code defines the `Manifest.cs` file required for an Orchard Core module. It uses the `[Module]` attribute to specify metadata such as the module's name, author, website, version, and description, which Orchard Core uses to discover and identify the module. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/getting-started/templates/README.md#_snippet_10 LANGUAGE: C# CODE: ``` using OrchardCore.Modules.Manifest; [assembly: Module( Name = "TemplateModule.OrchardCore", Author = "The Orchard Team", Website = "http://orchardproject.net", Version = "0.0.1", Description = "Template module." )] ``` -------------------------------- TITLE: Configuring Parcel Bundling in Assets.json (JSON) DESCRIPTION: Example Assets.json configuration using the `bundleEntrypoint` parameter to bundle assets. When using `bundleEntrypoint`, the `dest` parameter is not required. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/assets-manager/README.md#_snippet_3 LANGUAGE: json CODE: ``` [   {     "action": "parcel",     "name": "module-microsoft-datasource-wrapper",     "source": "Assets/Scripts/datasource-wrapper.js", "bundleEntrypoint": "bundle-name",     "tags":["vue3"]   } ] ``` -------------------------------- TITLE: Defining Queries Recipe Step in JSON DESCRIPTION: This JSON snippet illustrates how to define a 'queries' step within an OrchardCore recipe. It allows you to create or update queries programmatically during site setup, specifying the query name, source, and source-specific properties. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/Queries/README.md#_snippet_2 LANGUAGE: JSON CODE: ``` { "name": "queries", "Queries": [ { // Common properties "Name": "AwesomeQuery", "Source": "Lucene", // Properties of the concrete query ... } ] } ``` -------------------------------- TITLE: Running the Orchard Core Web Application (.NET CLI) DESCRIPTION: Starts the main web application project (`OrchardCore.Mvc.Web`) using the .NET CLI `dotnet run --project` command. This compiles and launches the application, making it available via HTTP/S and allowing you to test the integrated web app and module. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/guides/create-modular-application-mvc/README.md#_snippet_5 LANGUAGE: .NET CLI CODE: ``` dotnet run --project .\OrchardCore.Mvc.Web\OrchardCore.Mvc.Web.csproj ``` -------------------------------- TITLE: Default Widget Rendering Output HTML Example DESCRIPTION: Illustrates the default HTML structure produced when a Widget content item, such as a Paragraph widget, is rendered, including the wrapper elements automatically added by the Layers module for features like titles. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/src/docs/reference/modules/Widgets/README.md#_snippet_0 LANGUAGE: HTML CODE: ```

A Paragraph

This is a paragraph

``` -------------------------------- TITLE: Running CMS E2E Tests (Bash) DESCRIPTION: Executes the automated end-to-end tests specifically designed for the Orchard Core CMS features. This command is commonly used for CI/CD pipelines or automated test runs. SOURCE: https://github.com/orchardcms/orchardcore/blob/main/test/OrchardCore.Tests.Functional/Readme.md#_snippet_1 LANGUAGE: bash CODE: ``` npm run cms:test ```