Skip to content

Commit

Permalink
Adding frontend_css and js in configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
eerison committed Sep 2, 2022
1 parent 2548916 commit f4058bc
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
5 changes: 4 additions & 1 deletion docs/reference/advanced_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ Full configuration options:
stylesheets:
# Defaults:
- bundles/sonatapage/app.css
- bundles/sonatapage/frontend.css
javascripts:
frontend_stylesheets:
# Defaults:
- bundles/sonatapage/frontend.css
frontend_javascripts:
templates: # Required
# Prototype
id:
Expand Down
7 changes: 7 additions & 0 deletions docs/reference/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ SonataPageBundle Configuration
not_found: [404] # render 404 page with "not_found" key (name generated: _page_internal_error_{key})
fatal: [500] # so you can use the same page for different http errors or specify specific page for each error
# Add custom css and js for your pages.
# assets:
# frontend_javascripts:
# - js/your.js
# frontend_stylesheets:
# - css/your.css
SonataAdminBundle Configuration
-------------------------------

Expand Down
11 changes: 10 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,23 @@ public function getConfigTreeBuilder(): TreeBuilder
->arrayNode('stylesheets')
->defaultValue([
'bundles/sonatapage/app.css',
'bundles/sonatapage/frontend.css',
])
->prototype('scalar')->end()
->end()
->arrayNode('javascripts')
->defaultValue([])
->prototype('scalar')->end()
->end()
->arrayNode('frontend_stylesheets')
->defaultValue([
'bundles/sonatapage/frontend.css',
])
->prototype('scalar')->end()
->end()
->arrayNode('frontend_javascripts')
->defaultValue([])
->prototype('scalar')->end()
->end()
->end()
->end()

Expand Down
4 changes: 2 additions & 2 deletions src/Resources/views/base_layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ file that was distributed with this source code.

{% block sonata_page_stylesheets %}
{% block page_stylesheets %} {# Deprecated block #}
{% for stylesheet in sonata_page.assets.stylesheets %}
{% for stylesheet in sonata_page.assets.frontend_stylesheets %}
<link rel="stylesheet" href="{{ asset(stylesheet) }}" media="all">
{% endfor %}
{% endblock %}
Expand All @@ -34,7 +34,7 @@ file that was distributed with this source code.
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

{% for js in sonata_page.assets.javascripts %}
{% for js in sonata_page.assets.frontend_javascripts %}
<script src="{{ asset(js) }}"></script>
{% endfor %}
{% endblock %}
Expand Down
10 changes: 8 additions & 2 deletions tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,12 @@ public function testPageWithMatrix(): void
'assets' => [
'stylesheets' => [
'bundles/sonatapage/app.css',
'bundles/sonatapage/frontend.css',
],
'javascripts' => [],
'frontend_stylesheets' => [
'bundles/sonatapage/frontend.css',
],
'frontend_javascripts' => [],
],
'templates_admin' => [
'list' => '@SonataPage/PageAdmin/list.html.twig',
Expand Down Expand Up @@ -194,9 +197,12 @@ public function testPageWithoutMatrix(): void
'assets' => [
'stylesheets' => [
'bundles/sonatapage/app.css',
'bundles/sonatapage/frontend.css',
],
'javascripts' => [],
'frontend_stylesheets' => [
'bundles/sonatapage/frontend.css',
],
'frontend_javascripts' => [],
],
'templates_admin' => [
'list' => '@SonataPage/PageAdmin/list.html.twig',
Expand Down

0 comments on commit f4058bc

Please sign in to comment.