PHPackages                             netgen/layouts-contentful - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. netgen/layouts-contentful

ActiveSymfony-bundle[Framework](/categories/framework)

netgen/layouts-contentful
=========================

Netgen Layouts &amp; Contentful integration

2.0.0(3mo ago)111.0k21MITPHPPHP ^8.4CI passing

Since Oct 2Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/netgen-layouts/layouts-contentful)[ Packagist](https://packagist.org/packages/netgen/layouts-contentful)[ RSS](/packages/netgen-layouts-contentful/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (13)Versions (22)Used By (1)

Netgen Layouts &amp; Contentful integration
===========================================

[](#netgen-layouts--contentful-integration)

Installation instructions
-------------------------

[](#installation-instructions)

### Installing Netgen Layouts

[](#installing-netgen-layouts)

Follow the instructions in Netgen Layouts documentation to [install Netgen Layouts](https://docs.netgen.io/projects/layouts/en/latest/getting_started/install_existing_project.html).

### Use Composer

[](#use-composer)

After completing standard Netgen Layouts installation, run the following command to install Contentful integration:

```
composer require netgen/layouts-contentful
```

Symfony Flex will automatically enable the bundle and import the routes.

### Configure Contentful bundle

[](#configure-contentful-bundle)

To work with Contentful resources, you need to configure a client for every space you wish to use. For every client, you need to specify the space ID and its token. You can get space IDs and tokens from the APIs section from your Contentful instance at [app.contentful.com](https://app.contentful.com)

```
# config/packages/contentful.yaml
contentful:
    delivery:
        main:
            token: your_space_token
            space: your_space_identifier
```

For more information, see Contentful bundle [official repo on Github](https://github.com/contentful/ContentfulBundle).

### Configure the CMF Routing component

[](#configure-the-cmf-routing-component)

The integration uses CMF routing component and its dynamic router to match routes and generate URLs to resources from Contentful. You need to enable the dynamic router in your configuration:

```
# config/packages/cmf_routing.yaml
cmf_routing:
    chain:
        routers_by_id:
            router.default: 200
            cmf_routing.dynamic_router: 100
    dynamic:
        default_controller: netgen_layouts.contentful.controller.view
        persistence:
            orm:
                enabled: true
```

For more information, see [CMF Routing docs on symfony.com](https://symfony.com/bundles/CMFRoutingBundle/current/index.html).

### Import the schema

[](#import-the-schema)

Import the routing and local content schema to the database.

```
php bin/console doctrine:schema:update
```

**Note:** Use the command with `--dump-sql` first to check that it will do only modifications related to this bundle, and then use it with parameter `--force`to do the actual changes.

### Configure authentication for Netgen Layouts

[](#configure-authentication-for-netgen-layouts)

It is highly recommended to secure the Netgen Layouts interface and allow only authenticated users in. For fresh Symfony installations the simplest way is to define an admin user in memory with the `ROLE_NGLAYOUTS_ADMIN` role and enable the HTTP basic auth firewall.

```
# config/packages/security.yaml
security:
    providers:
        users_in_memory:
            memory:
                users:
                    admin:
                        password: admin
                        roles: [ROLE_NGLAYOUTS_ADMIN]

    password_hashers:
        Symfony\Component\Security\Core\User\InMemoryUser: plaintext

    firewalls:
        main:
            provider: users_in_memory
            http_basic: ~

    access_control:
        - { path: ^/nglayouts/(api|(dev/)?app|admin), roles: ROLE_NGLAYOUTS_ADMIN }
        - { path: ^/cb, roles: ROLE_NGLAYOUTS_ADMIN }
```

### Verifying that Netgen Layouts works

[](#verifying-that-netgen-layouts-works)

Start the [Symfony CLI web server](https://symfony.com/download) with:

```
symfony server:start
```

Open [https://127.0.0.1:8000/nglayouts/admin/layouts](https://127.0.0.1:8000/nglayouts/admin/layouts/), give the admin credentials and you should be able to create new layouts.

### Optional: Run the sync command

[](#optional-run-the-sync-command)

To warmup the caching for spaces and content types as well as syncing Contentful entries locally run this command:

```
php bin/console contentful:sync
```

There is a limit on 100 entries in one run, so if there are more than 100 entries you can run the command multiple times.

### Optional: Configure webhook

[](#optional-configure-webhook)

To make local cache refresh when an entry or a content type changes in Contentful add the webhook configuration.

Go to Contentful space settings and create a webhook with:

- the full URL for webhook ()
- basic auth credentials if necessary
- additional `X-Space-Id` header with the related value
- checked Published, Unpublished and Delete events for Content types
- checked Published, Unpublished and Delete events for entries

### Optional: Implement custom sluggers

[](#optional-implement-custom-sluggers)

This bundle offer the possibility to implement custom sluggers to generate URLs for full content based pages. Out of the box there are 2 sluggers implemented:

- `simple` slugger - takes the name of the Contentful entry and makes the slug. This one is used by default
- `with_space` slugger - adds the space name before the entry name so the URL will have the format `/[space_name_slug]/[entry_name_slug]`

To implement a custom slugger you need to implement the `EntrySluggerInterface`. A `FilterSlugTrait` is provided so you can filter the slug as required by Contentful.

```
