-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Conversation
|
||
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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
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') | ||
)) |
There was a problem hiding this comment.
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.
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!