Configure your resource
Read the previous chapter to create a new resource.
Implements the Resource interface
To declare your resource as a Sylius one, you need to implement the Sylius\Component\Resource\Model\ResourceInterface
which requires you to implement a getId()
method.
Use the Resource attribute
We add the PHP attribute #[Resource]
to the Doctrine entity. It will configure your entity as a Sylius resource.
By default, it will have the app.book
alias in Sylius resource which is a concatenation of the application name and the resource name {application}.{name}
.
Advanced configuration
Configure the resource name
It defines the resource name.
On your Twig templates, the order
variable will be replaced by the cart
one.
As an example, on a show
operation following Twig variables will be available:
resource
App\Entity\Order
cart
App\Entity\Order
operation
Sylius\Resource\Metadata\Show
resource_metadata
Sylius\Resource\Metadata\ResourceMetadata
app
Symfony\Bridge\Twig\AppVariable
Configure the resource plural name
It defines the resource plural name.
On your Twig templates, the books
variable will be replaced by the library
one.
As an example, on an index
operation these Twig variables will be available:
resources
Pagerfanta\Pagerfanta
library
Pagerfanta\Pagerfanta
operation
Sylius\Resource\Metadata\Index
resource_metadata
Sylius\Resource\Metadata\ResourceMetadata
app
Symfony\Bridge\Twig\AppVariable
Configure the resource vars
It defines the simple vars that you can use on your templates.
You can use these vars on your Twig templates. These vars will be available on any operations for this resource.
Last updated