### Install Varnish with apt-get Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/caching-with-varnish.rst Installs the Varnish daemon on Ubuntu or Debian systems. After running this command, Varnish should be installed and started automatically. ```bash apt-get install varnish ``` -------------------------------- ### Setup Virtual Environment in Fish Shell Source: https://github.com/sulu/sulu-docs/blob/3.x/README.md Recommended commands to create and activate a virtual environment and install dependencies for the Fish shell. ```fish # Create virtual environment python3 -m venv venv # Activate virtual environment source venv/bin/activate.fish # Install dependencies pip install -r requirements.txt ``` -------------------------------- ### Setup Virtual Environment in Bash/Zsh Source: https://github.com/sulu/sulu-docs/blob/3.x/README.md Recommended commands to create and activate a virtual environment and install dependencies for Bash or Zsh shells. ```bash # Create virtual environment python3 -m venv venv # Activate virtual environment source venv/bin/activate # Install dependencies pip install -r requirements.txt ``` -------------------------------- ### Install ffmpeg-bundle Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/video-preview-images.rst Install the required php-ffmpeg library using composer. ```bash composer require php-ffmpeg/php-ffmpeg ``` -------------------------------- ### Install varnish-modules Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/caching-with-varnish.rst Install the required varnish-modules package to enable XKey invalidation support. ```bash apt-get install varnish-modules ``` -------------------------------- ### Start a node container with docker for building the admin frontend Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/build-admin-frontend.rst Starts a node container with the specified version and maps the current directory to /var/project. Optionally use another node version by adjusting the image tag, and check assets/admin/package.json for compatible npm versions. ```bash docker run --rm --interactive --tty --volume ${PWD}:/var/project node:24.11.1 /bin/bash # for completion: using another node version is possible by adjusting the tag of the node image # docker run --rm --interactive --tty --volume ${PWD}:/var/project node:22.11.0 /bin/bash # check the assets/admin/package.json for compatible npm versions ``` -------------------------------- ### Install VIPS on Linux Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/media/imagine-adapter.rst Commands to install VIPS development headers and the PHP extension on Linux. ```bash apt-get install libvips-dev composer require rokka/imagine-vips ``` -------------------------------- ### Start local web server Source: https://github.com/sulu/sulu-docs/blob/3.x/book/getting-started.rst Launch the PHP built-in server to serve both the administration and website applications. ```bash php -S localhost:8000 -t public/ config/router.php ``` -------------------------------- ### Install sulu/phpcr-migration-bundle Source: https://github.com/sulu/sulu-docs/blob/3.x/upgrades/upgrade-2.6-3.0.rst Installs the dedicated bundle that provides the PHPCR migration from the old content storage into the new Doctrine-based storage. ```bash composer require sulu/phpcr-migration-bundle ``` -------------------------------- ### Configure environment variables in .env.local Source: https://github.com/sulu/sulu-docs/blob/3.x/book/deployment.rst Example configuration for the application environment and database URL. ```bash APP_ENV=prod DATABASE_URL=... ``` -------------------------------- ### Example X-Cache-Tags header Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/http_cache.rst Example header sent by the tags handler, which is removed by Varnish. ```bash X-Cache-Tags: 22a92d46-74ab-46cc-b47c-486b4b8a06a7,cf4a07fe-91d0-41be-aed8-b1c9ee1eb72a ``` -------------------------------- ### Install composer dependencies Source: https://github.com/sulu/sulu-docs/blob/3.x/book/deployment.rst Command to install production dependencies with optimized autoloader. ```bash composer install --no-dev --optimize-autoloader --classmap-authoritative ``` -------------------------------- ### Install Imagick on Linux Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/media/imagine-adapter.rst Commands to install ImageMagick development headers and the PHP imagick extension on Linux. ```bash apt-get install libmagickwand-dev apt-get install php8.3-imagick ``` -------------------------------- ### Verify Varnish listening port with ps Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/caching-with-varnish.rst Shows the command to verify which port Varnish is listening on. The -a option in the output indicates the listening address; in this example it is port 6081, which is incorrect for a production setup. ```bash $ ps ax | grep varnish 6585 ? SLs 0:00 varnishd -f /home/daniel/.varnish/sulu.vcl -s malloc,1G -T 127.0.0.1:2000 -a 0.0.0.0:6081 6609 ? Sl 0:07 varnishd -f /home/daniel/.varnish/sulu.vcl -s malloc,1G -T 127.0.0.1:2000 -a 0.0.0.0:6081 ``` -------------------------------- ### Install npm dependencies and create the admin build Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/build-admin-frontend.rst Creates the administration interface build by installing npm dependencies and running the build. This runs inside the /var/project/assets/admin directory. ```bash cd /var/project/assets/admin npm install npm run build ``` -------------------------------- ### Install VIPS on Mac Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/media/imagine-adapter.rst Commands to install VIPS dependencies and the PHP extension on macOS. ```bash brew install pkg-config brew install vips pecl install vips composer require rokka/imagine-vips ``` -------------------------------- ### Configure Redis Cache Adapter Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/preview/index.rst Example configuration for using Redis as the preview cache adapter. ```yaml # config/packages/sulu_admin.yaml sulu_preview: cache_adapter: "cache.adapter.redis" framework: cache: default_redis_provider: 'redis://localhost' # this is default and not needed ``` -------------------------------- ### Install scheb/2fa packages via Composer Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/security/index.rst Install the base bundle and the packages for the desired two-factor methods (email, TOTP, backup codes, trusted device) using Composer. ```bash composer require scheb/2fa-bundle scheb/2fa-email scheb/2fa-totp scheb/2fa-backup-code scheb/2fa-trusted-device ``` -------------------------------- ### Example routes for error pages Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/custom-error-page.rst Example routes generated for different locales. These show the pattern for testing error pages on example.org. ```bash example.org/ch._twig_error_test ANY ANY example.org /ch/_error/{code}.{_format} example.org/en._twig_error_test ANY ANY example.org /en/_error/{code}.{_format} example.org/fr._twig_error_test ANY ANY example.org /fr/_error/{code}.{_format} example.org/de._twig_error_test ANY ANY example.org /de/_error/{code}.{_format} example.org._twig_error_test ANY ANY example.org /_error/{code}.{_format} ``` -------------------------------- ### Pull Request To-Do List Examples Source: https://github.com/sulu/sulu-docs/blob/3.x/developer/contributing/pull-requests.rst Examples of items to include in the 'To Do' section of a pull request when requirements are not yet met or work is in progress. ```text - [ ] Submit changes to the documentation - [ ] Document the BC breaks ``` ```text - [ ] Finish the code - [ ] Add tests as they have not been updated yet - [ ] Gather feedback for my changes ``` -------------------------------- ### Install GD extension in Docker Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/media/imagine-adapter.rst Commands to install GD and necessary image libraries in a Docker environment. ```bash RUN apt-get update && apt-get install -y : libfreetype6-dev libwebp-dev libjpeg62-turbo-dev libpng-dev && docker-php-ext-configure gd –with-freetype –with-jpeg –with-webp && docker-php-ext-install -j$(nproc) gd ``` -------------------------------- ### Full Varnish cache configuration example Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/caching-with-varnish.rst Complete configuration with debug enabled, cache max ages, and Varnish proxy client enabled with server address. ```yaml sulu_http_cache: debug: enabled: true tags: enabled: true cache: max_age: 240 # 4 minutes shared_max_age: 480 # 8 minutes proxy_client: symfony: enabled: false varnish: enabled: true servers: [ '127.0.0.1:80' ] ``` -------------------------------- ### Install Imagick on Mac Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/media/imagine-adapter.rst Commands to install ImageMagick and the PHP imagick extension on macOS. ```bash brew install imagemagick pecl install imagick ``` -------------------------------- ### Build admin interface with npm Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/build-admin-frontend.rst Navigate to the admin assets directory, install dependencies with npm, and run the build command to create the administration interface. ```bash cd /var/project/assets/admin npm install npm run build ``` -------------------------------- ### Set database connection string Source: https://github.com/sulu/sulu-docs/blob/3.x/book/getting-started.rst Example of setting the DATABASE_URL environment variable for MySQL in .env.local. ```bash DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7 ``` -------------------------------- ### Run bundle tests with initialization Source: https://github.com/sulu/sulu-docs/blob/3.x/developer/contributing/test-your-code.rst Initializes the test database and runs all tests except component tests. Use the -i flag to initialize the test setup, and -C to skip component tests. ```bash $ ./bin/runtests -i -C ``` -------------------------------- ### Extended single_media_selection property with parameters Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/property-types/single_media_selection.rst An example showing how to restrict asset types and configure display options for the selection. ```xml Image ``` -------------------------------- ### Build admin interface with bun Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/build-admin-frontend.rst Navigate to the admin assets directory, run the preinstall and install commands with bun, then run the build command. Bun support is experimental and may be removed in future Sulu versions. ```bash cd /var/project/assets/admin bun run preinstall bun install bun run build ``` -------------------------------- ### Start the web server with custom IP and port Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/web-server/built-in.rst Changes the IP and port of the web server by passing them as arguments to the command. ```bash php -S 192.168.0.1:8080 -t public/ config/router.php ``` -------------------------------- ### Install WebpackEncoreBundle Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/webpack-encore.rst Add the WebpackEncoreBundle dependency to your project using Composer. ```bash composer require symfony/webpack-encore-bundle ``` -------------------------------- ### Route parts XML example Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/route/index.rst Shows how to tag properties with sulu.rlp.part to include them in the object variable for route schema. ```xml ``` -------------------------------- ### EventController example Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/route/index.rst Controller action that receives an Event entity and renders a template. ```php namespace App\Controller; use App\Entity\Event; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; class EventController extends AbstractController { public function indexAction(Event $event): Response { return $this->render('events/event.html.twig', ['event' => $event]); } } ``` -------------------------------- ### PHP setTargets example Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/link-provider.rst Shows how to restrict link targets to '_blank' and '_self' using setTargets() on the builder. ```php ->setTargets(['_blank', '_self']) ``` -------------------------------- ### Debug header output Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/http_cache.rst Example of the debug header added to the response. ```bash X-Cache: HIT/MISS ``` -------------------------------- ### Basic single_media_selection property configuration Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/property-types/single_media_selection.rst A minimal example of defining a single_media_selection property in a Sulu XML configuration. ```xml Document ``` -------------------------------- ### Extended XML example with request_parameters rootKey Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/property-types/single_category_selection.rst Adds an 'entry category' for the selection tree by passing a 'request_parameters' collection with a 'rootKey' parameter set to 'my_category_key'. ```xml Single Category Selection ``` -------------------------------- ### Build Documentation with Make Source: https://github.com/sulu/sulu-docs/blob/3.x/README.md Execute the build process to generate HTML documentation files in the _build/html folder. ```bash make html ``` -------------------------------- ### Run all tests without initialization Source: https://github.com/sulu/sulu-docs/blob/3.x/developer/contributing/test-your-code.rst Runs all tests after the initial setup. The -i flag is omitted because the database is already initialized. ```bash $ ./bin/runtests -a ``` -------------------------------- ### Event entity JSON serialization example Source: https://github.com/sulu/sulu-docs/blob/3.x/book/extend-admin.rst Example JSON representation of an event entity as expected by Sulu's frontend components. This object is sent to POST (without ID) and PUT actions, and returned by GET actions. ```json { "id": 1, "name": "Sulu Con 2020", "startDate": "2020-10-24T08:00:00", "endDate": "2020-10-25T18:00:00" } ``` -------------------------------- ### Add domain to hosts file Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/web-server/apache.rst Add the domain of your site to the hosts file (e.g., /etc/hosts on Unix or %SystemRoot%\System32\drivers\etc\hosts on Windows) to map it to your local machine. The example uses 127.0.0.1 for example.org. ```text # ... 127.0.0.1 example.org ``` -------------------------------- ### Template group XML example Source: https://github.com/sulu/sulu-docs/blob/3.x/book/templates.rst Shows a template configuration file with a element to place the template in a group. Templates without a element are placed in the implicit 'default' group. ```xml ``` -------------------------------- ### Twig rendering for single_account_selection Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/property-types/single_account_selection.rst Example of how to access the account object and resolve its logo image using the sulu_resolve_media function. ```twig {% set account = content.account %} {{ account.name }} {% if account.logo %} {% set image = sulu_resolve_media(account.logo, app.request.locale) %} {{ account.name }} {% endif ``` -------------------------------- ### Define a global block in XML Source: https://github.com/sulu/sulu-docs/blob/3.x/book/templates.rst Create an XML file in config/templates/blocks to define a reusable block type. The example defines a block with key 'text_block' and properties 'title' and 'description'. ```xml ``` -------------------------------- ### Build database and fixtures Source: https://github.com/sulu/sulu-docs/blob/3.x/book/deployment.rst Command to create the database and set up fixtures and search indexes for the first deployment. ```bash php bin/console sulu:build dev ``` -------------------------------- ### Display help text with info_text element Source: https://github.com/sulu/sulu-docs/blob/3.x/book/templates.rst Add a help text to a property by placing an info_text element inside the meta section. The lang attribute specifies the language of the help text. In this example, the help text explains that if the end date is the same as the start date, the event is treated as a one-day event. ```xml ``` -------------------------------- ### Clone repository and navigate to project directory Source: https://github.com/sulu/sulu-docs/blob/3.x/book/deployment.rst Commands to create the deployment directory, clone the repository, and change into the project directory. ```bash cd /var/www git clone example.org cd example.org ``` -------------------------------- ### Initialize new webspace Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/create-new-webspace.rst Run this command to initialize the new webspace after clearing the cache. ```bash php bin/console sulu:page:initialize ``` -------------------------------- ### Configure Central Cache in cache.yaml Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/preview/index.rst Recommended configuration for multi-server setups to use a central cache like Redis. ```yaml # config/packages/cache.yaml framework: cache: default_redis_provider: '%env(REDIS_CACHE)%' # REDIS_CACHE can be set in your .env files app: cache.adapter.redis # prefix_seed: 'my_project_%kernel.environment%' # unique name for the project installation to avoid cache conflicts between multiple installations ``` -------------------------------- ### Generate URL with RouteGeneratorInterface Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/route/index.rst Inject RouteGeneratorInterface and call generate() with slug, locale, and webspace to produce a URL. The example shows the expected output as a comment. ```php use Sulu\Route\Application\Routing\Generator\RouteGeneratorInterface; class EventController extends AbstractController { public function __construct( private RouteGeneratorInterface $routeGenerator, ) { } public function showAction(Event $event): Response { $url = $this->routeGenerator->generate( slug: '/events/my-event', locale: 'en', webspace: 'example', ); // $url = 'https://example.com/en/events/my-event' } } ``` -------------------------------- ### Configure scheb_2fa.yaml for enabled methods Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/security/index.rst Enable the installed two-factor methods (email, TOTP, backup codes, trusted device) in the scheb_2fa.yaml configuration file. The commented lines show the alternative for Google Authenticator. ```yaml scheb_two_factor: email: enabled: true sender_email: "%env(SULU_ADMIN_EMAIL)%" totp: enabled: true issuer: 'Sulu' # or, when scheb/2fa-google-authenticator is installed instead of scheb/2fa-totp: # google: # enabled: true # issuer: 'Sulu' backup_codes: enabled: true trusted_device: enabled: true ``` -------------------------------- ### Iterate over tags with sulu_tags Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/twig-extensions/functions/sulu_tags.rst This example demonstrates how to use the sulu_tags function to list all tags in the system and generate their corresponding URLs using sulu_tag_url. ```jinja ``` -------------------------------- ### Booting Kernel in Website Context for Integration Tests Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/test.rst Use Sulu's KernelTestCase to boot the kernel in the website context, ensuring access to services specific to that context. ```php // tests/Integration/Service/NewsletterGeneratorTest.php namespace App ests\Integration\Service; use Sulu\Bundle\TestBundle\Testing\KernelTestCase; use Sulu\Component\HttpKernel\SuluKernel; class NewsletterGeneratorTest extends KernelTestCase { public function testSomething() { self::bootKernel([ 'sulu.context' => SuluKernel::CONTEXT_WEBSITE ]); // ... } } ``` -------------------------------- ### Registering entity references with ReferenceStoreInterface::add Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/reference-store.rst Inject the ReferenceStoreInterface service and call its add method with the entity id and resource key to register a loaded entity. Here, the resource key is 'examples'. ```php referenceStore->add($id, 'examples'); } } ``` -------------------------------- ### XML property configuration for media_selection Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/property-types/media_selection.rst Example of defining a media_selection property named 'images' with allowed types (image,video), display options for positions, and a default display option of 'left'. ```xml Images ``` -------------------------------- ### Populate database for production Source: https://github.com/sulu/sulu-docs/blob/3.x/book/getting-started.rst Build the database for the production environment without adding the default 'admin' user. ```bash php bin/adminconsole sulu:build prod ``` -------------------------------- ### Remove stimulus import from app.js Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/webpack-encore.rst Remove these lines from assets/website/app.js to uninstall the stimulus library before installing web-js. This is part of the web-js installation steps. ```diff - // start the Stimulus application - import './bootstrap'; ``` -------------------------------- ### Implement ExampleSmartContentProvider Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/smart-content-data-provider.rst Create a custom provider by implementing SmartContentProviderInterface. The getConfiguration method uses the Builder to define filtering, sorting, and view options, while findFlatBy must return an array of IDs and titles. ```php enableTags() ->enableCategories() ->enableLimit() ->enablePagination() ->enableSorting([ ['column' => 'created', 'title' => 'sulu_admin.created'], ['column' => 'title', 'title' => 'sulu_admin.title'], ]) ->enableTypes([ ['type' => 'example-type-1', 'title' => 'app.example_type_1'], ['type' => 'example-type-2', 'title' => 'app.example_type_2'], ]) ->enableView('app.example_edit_form', ['id' => 'id']) ->getConfiguration(); } public function countBy(array $filters, array $params = []): int { return $this->repository->countByFilters($filters); } /** * @return array */ public function findFlatBy(array $filters, array $sortBys, array $params = []): array { $entities = $this->repository->findByFilters($filters, $sortBys, $params); return array_map( static fn (Example $entity) => [ 'id' => (string) $entity->getId(), 'title' => $entity->getTitle(), ], $entities, ); } public function getType(): string { return 'examples'; } public function getResourceLoaderKey(): string { return ExampleResourceLoader::RESOURCE_LOADER_KEY; } } ``` -------------------------------- ### Initialize Git repository Source: https://github.com/sulu/sulu-docs/blob/3.x/book/getting-started.rst Commands to initialize a Git repository and perform the first commit for your new project. ```bash cd my-project git init git add . git commit -m "Initial commit" ``` -------------------------------- ### Configure Varnish default.vcl for XKey Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/caching-with-varnish.rst Configure the Varnish VCL file to include Sulu and FOS tags, and set up grace mode and XKey handling. ```varnish4 # /etc/varnish/default.vcl vcl 4.0; include "/vendor/sulu/sulu/src/Sulu/Bundle/HttpCacheBundle/Resources/varnish/sulu.vcl"; include "/vendor/friendsofsymfony/http-cache/resources/config/varnish/fos_tags_xkey.vcl"; acl invalidators { "localhost"; } backend default { .host = "127.0.0.1"; .port = "8090"; } sub vcl_recv { call fos_tags_xkey_recv; call sulu_recv; # Force the lookup, the backend must tell not to cache or vary on all # headers that are used to build the hash. return (hash); } sub vcl_backend_response { set beresp.grace = 2m; call sulu_backend_response; } sub vcl_deliver { call fos_tags_xkey_deliver; call sulu_deliver; } ``` -------------------------------- ### Bootstrap a new Sulu project Source: https://github.com/sulu/sulu-docs/blob/3.x/book/getting-started.rst Use Composer to create a new project based on the Sulu Skeleton. ```bash composer create-project sulu/skeleton my-project -n ``` -------------------------------- ### Load Configuration and Define Services in SuluBookExtension.php Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/implement-entity-extensible.rst Reads the configuration and maps services to the container, including setting aliases for autowiring. ```php processConfiguration($configuration, $configs); (...) $this->configurePersistence($config['objects'], $container); $container->addAliases( [ 'Sulu\Bundle\BookBundle\Entity\BookRepositoryInterface' => 'sulu.repository.book', ], ); } (...) } ``` -------------------------------- ### sulu_tag_url_append Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/twig-extensions/functions/sulu_tag_url_append.rst Returns the current URL with the given tag appended to the GET parameter. ```APIDOC ## `sulu_tag_url_append` ### Description Returns the current URL with the given tag appended to the GET parameter. ### Arguments - **tag** (array) - Required - Serialized Tag instance to determine value - **tagsParameter** (string) - Optional - The name of the tags parameter (default: "tags") ### Returns - **string** - The current URL with the given tag in the tags parameter ``` -------------------------------- ### Minimal Sulu template with property types Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/property-types/index.rst A minimal Sulu template XML example showing the required structure with a 'properties' tag containing 'title' and 'url' properties. It includes the template key, view, controller, cache lifetime, and meta information. ```xml ``` -------------------------------- ### Twig Template Usage Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/property-types/checkbox.rst Example of how to check the value of the checkbox property in a Twig template. ```twig {% if content.available %} {# ... #} {% endif %} ``` -------------------------------- ### Populate database with default data Source: https://github.com/sulu/sulu-docs/blob/3.x/book/getting-started.rst Build the database for the development environment. Note that this adds a default 'admin' user. ```bash php bin/adminconsole sulu:build dev ``` -------------------------------- ### Basic webspace XML configuration Source: https://github.com/sulu/sulu-docs/blob/3.x/book/webspaces.rst Full XML configuration for a basic Sulu webspace with a single portal, multiple localizations, security, templates, navigation, segments, and resource locator strategy. The key must be unique across all webspaces in an installation. ```xml Website website website default default overview Mainnavigation Winter Winter Summer Sommer tree_leaf_edit Website website example.org example.localhost ``` -------------------------------- ### Define single_contact_selection in XML Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/property-types/single_contact_selection.rst Example of how to define the single_contact_selection property type within a property configuration. ```xml Contact ``` -------------------------------- ### Build website assets with npm Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/webpack-encore.rst Run these commands in the root directory after making changes to assets/website to build your scripts and styles. The outcome can be seen in the browser easily. ```bash npm install npm run build ``` -------------------------------- ### Implement ExampleRepository for SmartContentProvider Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/smart-content-data-provider.rst A repository implementation providing findByFilters and countByFilters methods to query and count entities based on filters, sorting, and pagination. ```php createQueryBuilder('example'); // Apply filters (tags, categories, types, etc.) if (isset($filters['tags']) && !empty($filters['tags'])) { $queryBuilder->join('example.tags', 'tag') ->andWhere('tag.id IN (:tags)') ->setParameter('tags', $filters['tags']); } // Apply sorting foreach ($sortBys as $sortBy) { $queryBuilder->addOrderBy('example.' . $sortBy['column'], $sortBy['direction']); } // Apply pagination if (isset($params['limit'])) { $queryBuilder->setMaxResults($params['limit']); } if (isset($params['offset'])) { $queryBuilder->setFirstResult($params['offset']); } return $queryBuilder->getQuery()->getResult(); } public function countByFilters(array $filters): int { $queryBuilder = $this->createQueryBuilder('example') ->select('COUNT(example.id)'); // Apply same filters as findByFilters if (isset($filters['tags']) && !empty($filters['tags'])) { $queryBuilder->join('example.tags', 'tag') ->andWhere('tag.id IN (:tags)') ->setParameter('tags', $filters['tags']); } return (int) $queryBuilder->getQuery()->getSingleScalarResult(); } } ``` -------------------------------- ### Twig Template Rendering Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/property-types/page_selection.rst Example of how to iterate over selected pages and access their mapped properties in a Twig template. ```twig {% for page in content.pages %}

{{ page.excerptTitle|default(page.title) }}

{{ page.excerptDescription|default(page.article)|raw }}
Read more
{% endfor %} ``` -------------------------------- ### Usage of sulu_content_root_path in Twig Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/twig-extensions/functions/sulu_content_root_path.rst Example showing how to use the sulu_content_root_path function to generate a link to the content root. ```jinja Home ``` -------------------------------- ### Create Product Repository Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/property-resolver-and-resource-loader.rst Implement a repository with a findByFilters method to support batch loading of products based on IDs, locale, and published status. ```php $filters * @return Product[] */ public function findByFilters(array $filters): array { $queryBuilder = $this->createQueryBuilder('product'); // Filter by IDs if (isset($filters['ids']) && is_array($filters['ids'])) { $queryBuilder->andWhere('product.id IN (:ids)') ->setParameter('ids', $filters['ids']); } // Filter by locale if (isset($filters['locale'])) { $queryBuilder->andWhere('product.locale = :locale') ->setParameter('locale', $filters['locale']); } // Filter by published status if (isset($filters['published'])) { $queryBuilder->andWhere('product.published = :published') ->setParameter('published', $filters['published']); } return $queryBuilder->getQuery()->getResult(); } } ``` -------------------------------- ### Define image formats in config/image-formats.xml Source: https://github.com/sulu/sulu-docs/blob/3.x/book/image-formats.rst Example XML configuration for defining image formats with different scaling modes: fixed width (300x), fixed height (x200), fixed dimensions (300x200), and max dimensions with inset mode (300x200-inset). Formats are defined in config/image-formats.xml and generated on first request. ```xml ``` -------------------------------- ### Access collection data in Twig Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/property-types/single_collection_selection.rst Example of accessing the full name of the selected collection in a Twig template. ```twig {{ content.collection.fullName }} ``` -------------------------------- ### Define single_collection_selection in XML Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/property-types/single_collection_selection.rst Example of how to define the single_collection_selection property type within a Sulu property configuration. ```xml Collection ``` -------------------------------- ### Create new Sulu skeleton project and copy .git folder Source: https://github.com/sulu/sulu-docs/blob/3.x/upgrades/upgrade-1.6-2.0.rst Commands to create a new Sulu 2.0 project using composer create-project and copy the old .git folder to the new project root. This is the recommended first step for upgrading. ```bash composer create-project sulu/skeleton cp /.git ``` -------------------------------- ### Define text_area property in XML Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/property-types/text_area.rst Example configuration for a text_area property within a Sulu XML property definition. ```xml Description ``` -------------------------------- ### Iterate over categories in Twig Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/twig-extensions/functions/sulu_categories.rst This example demonstrates how to list categories using sulu_categories and generate URLs for them using sulu_category_url. ```jinja ``` -------------------------------- ### Output text_line content in Twig Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/property-types/text_line.rst Twig example showing how to output the content of the text_line property using content.title. ```twig {{ content.title }} ``` -------------------------------- ### Creating a Website Client for Functional Tests Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/test.rst Use SuluTestCase to create a client in the website context for functional testing of controllers. ```php // tests/Functional/Controller/Website/RegistrationControllerTest.php namespace App\Tests\Functional\Controller\Website; use Sulu\Bundle\TestBundle\Testing\SuluTestCase; use Sulu\Component\HttpKernel\SuluKernel; class RegistrationControllerTest extends SuluTestCase { public function testIndexAction(): void { $client = static::createWebsiteClient(); $crawler = $client->request('GET', '/registration/'); $this->assertResponseIsSuccessful(); $this->assertSelectorTextContains('h1', 'Join our Community'); // ... } } ``` ```php $client = static::createClient([ 'sulu.context' => SuluKernel::CONTEXT_WEBSITE, ]); ``` -------------------------------- ### Configure PreviewBundle in sulu_admin.yaml Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/preview/index.rst Basic configuration for the PreviewBundle, including mode and cache adapter settings. ```yaml # config/packages/sulu_admin.yaml sulu_preview: mode: 'auto' # can be set to 'off' to disable the preview cache_adapter: 'cache.app' # where the preview cache is stored ``` -------------------------------- ### Access location data in Twig Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/property-types/location.rst Example of how to access various geographic attributes of the location property in a Twig template. ```twig {{ content.location.lat }}
{{ content.location.long }}
{{ content.location.street }}
{{ content.location.number }}
{{ content.location.code }}
{{ content.location.town }}
{{ content.location.country }}
{{ content.location.title }}
{{ content.location.zoom }} ``` -------------------------------- ### Implement TeaserProviderInterface for custom recipes Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/property-types/teaser_selection.rst Implements TeaserProviderInterface to expose custom recipe data as teasers. The getConfiguration() method defines the teaser selection UI, and find() returns Teaser objects for the given IDs and locale. ```php translator->trans('app.recipe', [], 'admin'), 'recipes', 'table', ['title'], $this->translator->trans('app.select_recipe', [], 'admin'), 'app.recipe_edit_form', ['id' => 'id'], ); } /** * @param array $ids * * @return Teaser[] */ public function find(array $ids, string $locale): array { if (0 === \count($ids)) { return []; } $recipes = $this->recipeRepository->findByIds($ids, $locale); $teasers = []; foreach ($recipes as $recipe) { $teasers[] = new Teaser( $recipe->getId(), 'recipes', $locale, $recipe->getTitle() ?? '', $recipe->getDescription() ?? '', $recipe->getMoreText() ?? '', $recipe->getUrl(), $recipe->getImageId(), [], ); } return $teasers; } } ``` -------------------------------- ### Define location property in XML Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/property-types/location.rst Example of how to define a location property within a Sulu XML configuration file. ```xml Location ``` -------------------------------- ### Download administration languages Source: https://github.com/sulu/sulu-docs/blob/3.x/book/getting-started.rst Run this command to download the languages configured in the YAML file. ```bash php bin/console sulu:admin:download-language ``` -------------------------------- ### Load snippet by area Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/twig-extensions/functions/sulu_snippet_load_by_area.rst Example of using the sulu_snippet_load_by_area function to retrieve a snippet for the 'sidebar_overview' area and access its title property. ```jinja {% set snippets = sulu_snippet_load_by_area('sidebar_overview') %} {{ snippets.content.title }} ``` -------------------------------- ### Configure resources in sulu_admin.yaml Source: https://github.com/sulu/sulu-docs/blob/3.x/book/extend-admin.rst Place this configuration in /config/packages/sulu_admin.yaml to map the resource key 'events' to the list and detail routes. ```yaml sulu_admin: resources: events: routes: list: app.get_events detail: app.get_event ``` -------------------------------- ### Render contact in Twig Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/property-types/single_contact_selection.rst Example of accessing the contact object and rendering its full name and avatar using the sulu_resolve_media function. ```twig {% set contact = content.contact %} {{ contact.fullName }} {% if contact.avatar %} {% set image = sulu_resolve_media(contact.avatar, app.request.locale) %} {{ contact.fullName }} {% endif %} ``` -------------------------------- ### Route schema using object parts Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/route/index.rst Example of a route_schema parameter that uses tagged properties via the object variable. ```xml ``` -------------------------------- ### Run the update build command (sulu:admin:update-build) Source: https://github.com/sulu/sulu-docs/blob/3.x/cookbook/build-admin-frontend.rst Use this command to update the administration interface build. It downloads the build for your project from the sulu/skeleton repository if possible. If custom JavaScript code is present, the command cleans up leftovers from previous builds and builds the JavaScript manually on your system, which requires Node.js. ```bash php bin/adminconsole sulu:admin:update-build ``` -------------------------------- ### sulu_tag_url_clear() Source: https://github.com/sulu/sulu-docs/blob/3.x/reference/twig-extensions/functions/sulu_tag_url_clear.rst Returns the current URL with the given GET parameter (e.g., 'tags') removed. Accepts an optional parameter name. ```APIDOC ## sulu_tag_url_clear() ### Description Returns the current URL and clears the given GET parameter. ### Method Twig Function ### Function Signature `sulu_tag_url_clear(tagsParameter)` ### Parameters - **tagsParameter** (string) - Optional - The name of the GET parameter to clear. Default: "tags" ### Return Value - **string** - Current URL without the specified tags parameter. ``` -------------------------------- ### Configure webspace in website.xml Source: https://github.com/sulu/sulu-docs/blob/3.x/book/getting-started.rst Set the name and unique key for your project's webspace in the XML configuration file. ```xml My Project my-project ``` -------------------------------- ### Configure Website Routes Source: https://github.com/sulu/sulu-docs/blob/3.x/bundles/audience_targeting.rst Add the website routes to your routing configuration file. ```yaml # ... sulu_audience_targeting: resource: "@SuluAudienceTargetingBundle/Resources/config/routing_website.yml" ``` -------------------------------- ### Cleanup Obsolete Image Formats Source: https://github.com/sulu/sulu-docs/blob/3.x/book/image-formats.rst Removes generated image formats for media that no longer exist in the database, useful in multi-server setups. ```bash php bin/websiteconsole sulu:media:format:cache:cleanup ```