Any page can be defined as a content fragment that can be injected into different parts of your site via twig hooks.
As for pages, fragments can be:
enabled or disabled globally
enabled or disabled for a specific channel
subject to publication scheduling
Trying to access a page defined as a fragment in your storefront, will result in a 404 - Not found status code.
🧱 Defining content fragments
To define fragments, create the config/packages/fiftydeg_sylius_degditor_base.yaml file in your project and configure them like in following examples.
Static content fragments
1fifty_deg_sylius_degditor_base:23fragments:4'sylius_shop.product.show.content#shared_fragment':# Fragment unique key5name:'Product shared content'# Fragment name, shown while editing the page6description:'Content shared by all products in your catalog'# Fragment description, shown while editing the page7
In the example above, we're defining a static fragment that can be used anywhere in your storefront.
The editor, on the admin side, will be able to search and select this fragment when creating / editing a page.
Dynamic content fragments:
1fifty_deg_sylius_degditor_base:23fragments:4'@.sylius_shop.product.show.content#product_fragment':5name:'Product content'6description:'Content shown in a specific product page'7entity_repository:'sylius.repository.product'8entity_property:'code'9
In the example above, we're defining dynamic fragments that must be used in specific pages of your storefront (in this case in a Product detail page).
To define dynamic fragments, you need to:
use the @ symbol somewhere in the yaml key
define a repository from where to fetch entities
define the entity property that will be used to dynamically replace the @ symbol
Let's assume the catalog contains two products with the following code attribute product_1 and product_2, the example above generates the following content fragments keys:
As you can see in the example above, you can define fallback content fragments in case the main fragment has not been found.
This can be achieved through the fallbackFragments array: the first available content fragment found in the array will replace the main fragment.
🗝️ Property access
When configuring entity_property you can access properties from related entities such as product.mainTaxon.code since, behind the scenes, we're using Symfony Property Access.
1fifty_deg_sylius_degditor_base:23fragments:4'@.sylius_shop.product.show.content#fallback_fragment':5name:'Product fallback content'6description:'Fallback content based on product main taxon'7entity_repository:'sylius.repository.product'8entity_property:'mainTaxon.code'9