Skip to content

Commit

Permalink
minor symfony#10020 Removed more PHP template examples (javiereguiluz)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.8 branch (closes symfony#10020).

Discussion
----------

Removed more PHP template examples

In symfony#10014 I forgot to apply the script to some files, so this PR fixes that.

Commits
-------

c02b5cc Removed more PHP template examples
  • Loading branch information
javiereguiluz committed Jul 5, 2018
2 parents 6d940aa + c02b5cc commit 3e93523
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 749 deletions.
48 changes: 13 additions & 35 deletions controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -417,47 +417,25 @@ you'll use this key to retrieve the message.
In the template of the next page (or even better, in your base layout template),
read any flash messages from the session:

.. configuration-block::
.. code-block:: html+twig

.. code-block:: html+twig
{# app/Resources/views/base.html.twig #}

{# app/Resources/views/base.html.twig #}
{# you can read and display just one flash message type... #}
{% for flash_message in app.session.flashBag.get('notice') %}
<div class="flash-notice">
{{ flash_message }}
</div>
{% endfor %}

{# you can read and display just one flash message type... #}
{% for flash_message in app.session.flashBag.get('notice') %}
<div class="flash-notice">
{# ...or you can read and display every flash message available #}
{% for type, flash_messages in app.session.flashBag.all %}
{% for flash_message in flash_messages %}
<div class="flash-{{ type }}">
{{ flash_message }}
</div>
{% endfor %}

{# ...or you can read and display every flash message available #}
{% for type, flash_messages in app.session.flashBag.all %}
{% for flash_message in flash_messages %}
<div class="flash-{{ type }}">
{{ flash_message }}
</div>
{% endfor %}
{% endfor %}

.. code-block:: html+php

<!-- app/Resources/views/base.html.php -->

// you can read and display just one flash message type...
<?php foreach ($view['session']->getFlashBag()->get('notice') as $message): ?>
<div class="flash-notice">
<?php echo $message ?>
</div>
<?php endforeach ?>

// ...or you can read and display every flash message available
<?php foreach ($view['session']->getFlashBag()->all() as $type => $flash_messages): ?>
<?php foreach ($flash_messages as $flash_message): ?>
<div class="flash-<?php echo $type ?>">
<?php echo $message ?>
</div>
<?php endforeach ?>
<?php endforeach ?>
{% endfor %}

.. note::

Expand Down
38 changes: 10 additions & 28 deletions forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,12 @@ done by passing a special form "view" object to your template (notice the
``$form->createView()`` in the controller above) and using a set of form
helper functions:

.. configuration-block::

.. code-block:: html+twig

{# app/Resources/views/default/new.html.twig #}
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}

.. code-block:: html+php
.. code-block:: html+twig

<!-- app/Resources/views/default/new.html.php -->
<?php echo $view['form']->start($form) ?>
<?php echo $view['form']->widget($form) ?>
<?php echo $view['form']->end($form) ?>
{# app/Resources/views/default/new.html.twig #}
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}

.. image:: /_images/form/simple-form.png
:align: center
Expand Down Expand Up @@ -432,21 +423,12 @@ Validation is a very powerful feature of Symfony and has its own
but are being prevented by your browser from, for example, submitting
blank fields.

.. configuration-block::

.. code-block:: html+twig

{# app/Resources/views/default/new.html.twig #}
{{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }}
{{ form_widget(form) }}
{{ form_end(form) }}

.. code-block:: html+php
.. code-block:: html+twig

<!-- app/Resources/views/default/new.html.php -->
<?php echo $view['form']->start($form, array('attr' => array('novalidate' => 'novalidate') ?>
<?php echo $view['form']->widget($form) ?>
<?php echo $view['form']->end($form) ?>
{# app/Resources/views/default/new.html.twig #}
{{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }}
{{ form_widget(form) }}
{{ form_end(form) }}

.. index::
single: Forms; Built-in field types
Expand Down
73 changes: 18 additions & 55 deletions frontend/assetic/apply_to_option.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,11 @@ Filter a single File
You can now serve up a single CoffeeScript file as JavaScript from within your
templates:

.. configuration-block::

.. code-block:: html+twig

{% javascripts '@AppBundle/Resources/public/js/example.coffee' filter='coffee' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
.. code-block:: html+twig

.. code-block:: html+php

<?php foreach ($view['assetic']->javascripts(
array('@AppBundle/Resources/public/js/example.coffee'),
array('coffee')
) as $url): ?>
<script src="<?php echo $view->escape($url) ?>"></script>
<?php endforeach ?>
{% javascripts '@AppBundle/Resources/public/js/example.coffee' filter='coffee' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}

This is all that's needed to compile this CoffeeScript file and serve it
as the compiled JavaScript.
Expand All @@ -92,27 +81,13 @@ Filter multiple Files

You can also combine multiple CoffeeScript files into a single output file:

.. configuration-block::

.. code-block:: html+twig
.. code-block:: html+twig

{% javascripts '@AppBundle/Resources/public/js/example.coffee'
'@AppBundle/Resources/public/js/another.coffee'
filter='coffee' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}

.. code-block:: html+php

<?php foreach ($view['assetic']->javascripts(
array(
'@AppBundle/Resources/public/js/example.coffee',
'@AppBundle/Resources/public/js/another.coffee',
),
array('coffee')
) as $url): ?>
<script src="<?php echo $view->escape($url) ?>"></script>
<?php endforeach ?>
{% javascripts '@AppBundle/Resources/public/js/example.coffee'
'@AppBundle/Resources/public/js/another.coffee'
filter='coffee' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}

Both files will now be served up as a single file compiled into regular JavaScript.

Expand Down Expand Up @@ -188,24 +163,12 @@ template. You can also list regular JavaScript files, all of which will be
combined and rendered as a single JavaScript file (with only the ``.coffee``
files being run through the CoffeeScript filter):

.. configuration-block::
.. code-block:: html+twig

{% javascripts '@AppBundle/Resources/public/js/example.coffee'
'@AppBundle/Resources/public/js/another.coffee'
'@AppBundle/Resources/public/js/regular.js' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}


.. code-block:: html+twig

{% javascripts '@AppBundle/Resources/public/js/example.coffee'
'@AppBundle/Resources/public/js/another.coffee'
'@AppBundle/Resources/public/js/regular.js' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}

.. code-block:: html+php

<?php foreach ($view['assetic']->javascripts(
array(
'@AppBundle/Resources/public/js/example.coffee',
'@AppBundle/Resources/public/js/another.coffee',
'@AppBundle/Resources/public/js/regular.js',
)
) as $url): ?>
<script src="<?php echo $view->escape($url) ?>"></script>
<?php endforeach ?>
Loading

0 comments on commit 3e93523

Please sign in to comment.