dev-master
9999999-devSymfony router for static pages
MIT
The Requires
The Development Requires
by Nacho Martin
file filesystem bundle generator symfony static router
Symfony router for static pages
This bundle provides a Symfony chained router that adds routes for static files in a directory., (*1)
Use case: You may want to integrate the product of a static content generator engine (Sphinx, Jekyll, you name it), or you simply have some html files in a directory and you want them to be a route in your Symfony app, because you want, for instance, to..., (*2)
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*3)
$ composer require limenius/filesystem-router-bundle
This bundle uses the Symfony CMF Dynamic router, so we need to configure it in our app/config.yml
file:, (*4)
cmf_routing: chain: routers_by_id: router.default: 200 cmf_routing.dynamic_router: 100 dynamic: route_provider_service_id: limenius_filesystem_router.route_provider templates_by_class: Limenius\Bundle\FilesystemRouterBundle\Document\ContentDocument: MyBundle:MyController:my_template.html.twig
Where in the last line, we have specified the template that will deal with the static content., (*5)
Also, we add some lines to confgure the bundle, (*6)
limenius_filesystem_router: collections: Docs: path: "%kernel.root_dir%/Resources/my_static_directory/" prefix: doc
collections
is a list of directories that you want to route.
Every collection have a required path
and an optional prefix
.
This bundle will create a route for every html
file found recursively in the path., (*7)
The template that we have specified will have a contentDocument
available:, (*8)
{{ contentDocument |raw }}
We can specify the controller that will receive the document with configuring the dynamic router with:, (*9)
cmf_routing: chain: routers_by_id: router.default: 200 cmf_routing.dynamic_router: 100 dynamic: route_provider_service_id: limenius_filesystem_router.route_provider controllers_by_type: filesystem_route: Acme\MyBundle\Controller\MyController::myAction
Where in the last line, we have specified the action that will deal with the static content., (*10)
The action will receive the contents of the file in the variable $contentDocument
., (*11)
It can be as simple as:, (*12)
/** * @Template() */ public function docsAction($contentDocument) { return array('content' => $contentDocument); }
With a template containing:, (*13)
{{ content | raw }}
Of course you can preprocess the document dealing with $contentDocument
, for instance crawling it to extract the title or other information., (*14)
Check out your new routes with the app/console router:debug
command., (*15)
Use the path of your file as in <a href="{{ url('manual/index.html')}}">Documentation</a>
, (*16)
By default, this bundle will only expose files with the extension html
. You can configure it with the option extensions_exposed
:, (*17)
limenius_filesystem_router: collections: Docs: path: "%kernel.root_dir%/Resources/my_docs/_build/html" prefix: docs extensions_exposed: ['html', 'txt']
This bundle is under the MIT license. See the complete license in the file:, (*18)
LICENSE.md
Symfony router for static pages
MIT
file filesystem bundle generator symfony static router