Skip to content

Proofing the templating chapter #7264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Proofing the templating chapter #7264

wants to merge 2 commits into from

Conversation

weaverryan
Copy link
Member

Hi guys!

In a training, I watched someone read the templating chapter and not quite understand how the controller and template work together. So, I added a little spot on top that shows both pieces together... then re-proofread this entire chapter.

Cheers!


But Symfony packages an even more powerful templating language called `Twig`_.
Twig allows you to write concise, readable templates that are more friendly
to web designers and, in several ways, more powerful than PHP templates:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This intro now felt a bit old and unnecessary

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the documentation is about the component right? The templating logic from the full stack is going to be deprecated, so is it worth it? Maybe would it be better to document the TwigBundle and the TwigBridge instead?

With the new navigation its not that easy to find some documentation about twig and doctrine integration. Only the PHPUnit Bridge is among the components, and there is none the bundles from the symfony repo among the list of bundles. Documenting them would be a also a place for some new and old cookbooks to link there.

Maybe this is worth a new issue, wdyt?

{% block body %}{% endblock %}
</div>
{% block body %}{% endblock %}
{% block javascripts %}{% endblock %}
</body>
</html>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced with the REAL base.html.twig... because users actually start with this :)

Assuming that AcmeBlogBundle lives at ``src/Acme/BlogBundle``, the
final path to the file would be ``src/Acme/BlogBundle/Resources/views/Blog/index.html.twig``.
Notice that ``@AcmeBlog`` does **not contain the word Bundle** at the end - this
should be left off.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My impression, is that the old FooBundle:Default:index.html.twig is out of style... and might even be removed someday (I might have just made that up... can't remember). And that the Twig namespaces are preferred. So, I thought - maybe we should just drop the old conversation, and just talk about the new Twig namespaces. There's less to explain, because the syntax is less weird.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Officially anything different from the Twig namespaces is considered legacy and it will be removed in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry just reading the discussion here after commenting above, but for me this change does not make any sense.

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nice improvements. Thanks Ryan.

* ``Blog``: (*directory*) indicates that the template lives inside the
``Blog`` subdirectory of ``Resources/views``;
*If* you need to refer to a template that lives in a bundle, Symfony uses a
``@bundle/Directory/filename.html.twig``. For example, suppose you have a bundle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here looks like a word is missing: Symfony uses a [...].

I would have used: Symfony uses [...]. or Symfony uses the [...] syntax.

return $this->render('lucky/number.html.twig', array(
// pass two variables into your template
'randomNumber' => $number,
'people' => array('Javier', 'Christian, 'Wouter')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a proposal ... what about removing our names here and using anonymous names with some more diversity (women, some non-European + non-American names, etc.) For example:

'people' => array('Anna', 'Cheng', 'John')

// renders app/Resources/views/lucky/number.html.twig
return $this->render('lucky/number.html.twig', array(
// pass two variables into your template
'randomNumber' => $number,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Twig naming convention uses snake_case for variable names (which btw matches the Symfony convention for array keys). So I would use random_number instead.


But Symfony packages an even more powerful templating language called `Twig`_.
Twig allows you to write concise, readable templates that are more friendly
to web designers and, in several ways, more powerful than PHP templates:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the documentation is about the component right? The templating logic from the full stack is going to be deprecated, so is it worth it? Maybe would it be better to document the TwigBundle and the TwigBridge instead?

With the new navigation its not that easy to find some documentation about twig and doctrine integration. Only the PHPUnit Bridge is among the components, and there is none the bundles from the symfony repo among the list of bundles. Documenting them would be a also a place for some new and old cookbooks to link there.

Maybe this is worth a new issue, wdyt?

$number = mt_rand(0, 10);

// renders app/Resources/views/lucky/number.html.twig
return $this->render('lucky/number.html.twig', array(
Copy link
Contributor

@HeahDude HeahDude Dec 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this with this syntax makes needless the use of this component, since it only needs twig integration, and this is why it will be deprecated.

This could work in silex too which works depending on the Twig Bridge only and doesn't use the Templating component at all.

Assuming that AcmeBlogBundle lives at ``src/Acme/BlogBundle``, the
final path to the file would be ``src/Acme/BlogBundle/Resources/views/Blog/index.html.twig``.
Notice that ``@AcmeBlog`` does **not contain the word Bundle** at the end - this
should be left off.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry just reading the discussion here after commenting above, but for me this change does not make any sense.

@HeahDude
Copy link
Contributor

I've just come across symfony/symfony-standard#861 (comment), which seems to be in concordance with my comments, right?

// pass two variables into your template
'randomNumber' => $number,
'people' => array('Javier', 'Christian, 'Wouter')
))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small nitpick, but a semicolon is missing here. That might be confusing for people who are new to PHP.

@weaverryan weaverryan closed this Jul 2, 2017
@xabbuh xabbuh deleted the template-proofing branch July 7, 2017 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants