agence-adeliom / easy-page-bundle
A simple lightweight CMS bundle for Symfony
Installs: 8 067
Dependents: 3
Suggesters: 0
Security: 0
Stars: 10
Watchers: 1
Forks: 6
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.0.2
- ext-json: *
- agence-adeliom/easy-common-bundle: ^2.0.122
- agence-adeliom/easy-seo-bundle: ^2.0.122
- easycorp/easyadmin-bundle: ^3.4 || ^v4.0
- stof/doctrine-extensions-bundle: ^1.6
- symfony/config: ^5.4 || ^6.0
- symfony/dependency-injection: ^5.4 || ^6.0
- symfony/deprecation-contracts: ^2.2 || ^v3.0
- symfony/event-dispatcher: ^5.4 || ^6.0
- symfony/form: ^5.4 || ^6.0
- symfony/framework-bundle: ^5.4 || ^6.0
- symfony/http-kernel: ^5.4 || ^6.0
- symfony/options-resolver: ^5.4 || ^6.0
- symfony/property-access: ^5.4 || ^6.0
- symfony/webpack-encore-bundle: ^1.10
- dev-main
- 3.x-dev
- 2.x-dev
- 2.0.122
- 2.0.121
- 2.0.120
- 2.0.119
- 2.0.118
- 2.0.117
- 2.0.116
- 2.0.115
- 2.0.114
- 2.0.112
- 2.0.111
- 2.0.110
- 2.0.109
- 2.0.108
- 2.0.107
- 2.0.106
- 2.0.105
- 2.0.104
- 2.0.103
- 2.0.102
- 2.0.101
- 2.0.100
- 2.0.99
- 2.0.98
- 2.0.97
- 2.0.96
- 2.0.95
- 2.0.94
- 2.0.93
- 2.0.92
- 2.0.91
- 2.0.90
- 2.0.89
- 2.0.88
- 2.0.87
- 2.0.86
- 2.0.85
- 2.0.84
- 2.0.83
- 2.0.82
- 2.0.81
- 2.0.80
- 2.0.79
- 2.0.78
- 2.0.77
- 2.0.76
- 2.0.75
- 2.0.74
- 2.0.73
- 2.0.72
- 2.0.71
- 2.0.70
- 2.0.69
- 2.0.68
- 2.0.67
- 2.0.66
- 2.0.65
- 2.0.64
- 2.0.63
- 2.0.62
- 2.0.61
- 2.0.60
- 2.0.59
- 2.0.57
- 2.0.56
- 2.0.55
- 2.0.54
- 2.0.53
- 2.0.52
- 2.0.49
- 2.0.48
- 2.0.47
- 2.0.46
- 2.0.45
- 2.0.44
- 2.0.43
- 2.0.42
- 2.0.41
- 2.0.40
- 2.0.39
- 2.0.38
- 2.0.37
- 2.0.36
- 2.0.35
- 2.0.34
- 2.0.33
- 2.0.32
- 2.0.31
- 2.0.30
- 2.0.29
- 2.0.28
- 2.0.27
- 2.0.26
- 2.0.25
- 2.0.24
- 2.0.23
- 2.0.22
- 2.0.19
- 2.0.18
- 2.0.17
- 2.0.16
- 2.0.15
- 2.0.10
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 1.0.1
- 1.0.0
- dev-develop
This package is auto-updated.
Last update: 2024-10-29 10:54:14 UTC
README
Easy Page Bundle
A basic CMS system for Easyadmin.
Installation with Symfony Flex
Add our recipes endpoint
{ "extra": { "symfony": { "endpoint": [ "https://api.github.com/repos/agence-adeliom/symfony-recipes/contents/index.json?ref=flex/main", ... "flex://defaults" ], "allow-contrib": true } } }
Install with composer
composer require agence-adeliom/easy-page-bundle
Versions
Setup database
Using doctrine migrations
php bin/console doctrine:migration:diff php bin/console doctrine:migration:migrate
Without
php bin/console doctrine:schema:update --force
Documentation
Manage pages in your Easyadmin dashboard
Go to your dashboard controller, example : src/Controller/Admin/DashboardController.php
<?php namespace App\Controller\Admin; ... use App\Entity\EasyPage\Page; class DashboardController extends AbstractDashboardController { ... public function configureMenuItems(): iterable { ... yield MenuItem::section('easy.page.admin.menu.contents'); // (Optional) yield MenuItem::linkToCrud('easy.page.admin.menu.pages', 'fa fa-file-alt', Page::class); ...
View page
The PageController handles some methods to view pages with a single index().
The URI for both is simply /{slug} where slug is the... page.
If your page has one parent, then the URI is the following: /{parentSlug}/{slug}.
You can notice that we respect the pages hierarchy in the generated url.
You can navigate through a complex list of pages, as long as they are related as parent and child.
This allows you to have such urls like this one : http://www.mysite.com/about/company/team/members for instance, will show only the members page, but its parent has a parent, that has a parent, and so on, until you reach the "root" parent. And it's the same behavior for categories.
Note: this behavior is the precise reason why you have to use a specific rules for your routing, unless you may have many "404" errors.
Generate a route based on a single page
If you have a Page
object in a view or in a controller, you can get the whole arborescence by using the getTree()
method, which will navigate through all parents and return a string based on a separator argument (default /
, for urls).
Let's get an example with this kind of tree:
/ - Home (root url)
├─ /welcome - Welcome page (set as "homepage", so "Home" will be the same)
│ ├─ /welcome/our-company - Our company
│ ├─ /welcome/our-company/financial - Financial
│ └─ /welcome/our-company/team - Team
└─ Contact
Imagine we want to generate the url for the "Team" page. You have this Page
object in your view/controller.
{# Page : "Team" #} {{ path('easy_page_index', {"slugs": page.tree}) }} {# Will show : /welcome/our-company/team #}
Or in a controller:
// Page : "Team" $url = $this->generateUrl('easy_page_index', ['slugs' => $page->getTree()]); // $url === /welcome/our-company/team
Homepage
The homepage is always the first Page
object with its template
attribute set to homepage
. Be sure to have only one element defined as homepage, or you may have unexpected results.
Design
You have some options to customize the design of your simple CMS.
Using different layouts
Obviously, the default layout has no style.
To change the layout, simply change the OrbitaleCmsBundle configuration to add your own layout:
# config/packages/easy_page.yml easy_page: layouts: front: { resource: @App/layout.html.twig } # The Twig path to your layout
Without overriding anything, you can easily change the layout for your CMS!
Take a look at the default layout to see which Twig blocks are mandatory to render correctly the pages.
Advanced layout configuration
The basic configuration for a layout is to specify a template to extend.
But if you look at the Configuration reference you will see that there are many other parameters you can use to define a layout:
Prototype of a layout configuration:
- name (attribute used as key for the layouts list):
The name of your layout. Simply for readability issues, and maybe to get it directly from the config (if you need it). - resource:
The Twig template used to render all the pages (see the above section) - assets_css and assets_js:
Any asset to send to the Twigasset()
function. The CSS is rendered in thestylesheets
block, and js in thejavascripts
block. - host:
The exact domain name you want the layout to match with. - pattern:
The regexp of the path you want to match with for this layout. It's nice if you want to use a different layout for pages. For example, you can specify a layout for the^/page/
pattern, and another for^/about-us/
. If you specify a very deep pattern, you can even change the layout for a single page!
Take another look on the config reference if you need to get the prototype defaults.
⚠️ Warning! The first matching layout will be used, as well as
routing would do, so be sure to configure them in the right order!
Empty values won't be taken in account.
Configuration reference
# config/packages/easy_page.yml easy_page: page_class: ~ # Required, must extend Easy Page class page_repository: Adeliom\EasyPageBundle\Repository\PageRepository page_controller: Adeliom\EasyPageBundle\Controller\PageController layouts: # Prototype name: name: ~ # Optional, it's automatically set from the key if it's a string resource: ~ # Required, must be a valid twig template assets_css: [] # Injected with the `asset()` twig function assets_js: [] # Injected with the `asset()` twig function assets_webpack: [] # Injected with the `encore_entry_link_tags()` and `encore_entry_script_tags()` twig functions pattern: ~ # Regexp host: ~ # Exact value cache: enabled: false ttl: 300