Problem/Motivation
menu.html.twig has a clever recursive macro, but according to the Twig documentation there is an unnecessary import inside of it.
We can see in the compiled Twig template that the import is doing an unnecessary variable reinitialization.
doDisplay method (main code path, doesn't change with this patch):
protected function doDisplay(array $context, array $blocks = array())
{
// line 16
$context["menus"] = $this;
// line 17
echo "
";
// line 22
echo $this->env->getExtension('drupal_core')->renderVar($context["menus"]->getmenu_links((isset($context["items"]) ? $context["items"] : null), (isset($context["attributes"]) ? $context["attributes"] : null), 0));
echo "
";
}
Before
ob_start();
try {
// line 25
echo " ";
$context["menus"] = $this;
// line 26
echo " ";
if ((isset($context["items"]) ? $context["items"] : null)) {
// line 27
After
ob_start();
try {
// line 25
echo " ";
if ((isset($context["items"]) ? $context["items"] : null)) {
// line 26
Because this is the only Twig macro (and only recursive Twig macro) in core it should probably set a better example.
Beta phase evaluation
Issue category | Task because nothing is broken |
---|---|
Issue priority | Normal because nothing is broken |
Unfrozen changes | Only changes templates. |
Prioritized changes | Not a prioritized change. |
Disruption | Not disruptive at all. If someone has overridden this template they can keep the overridden template and won't have any issues. |
Proposed resolution
Remove the unnecessary import from inside the macro.
Remaining tasks
Patch (both Classy and core's menu.html.twig)
Patch review
User interface changes
n/a
API changes
n/a
Comment | File | Size | Author |
---|---|---|---|
#8 | menu_html_twig_has_an-2501491-8.patch | 1.51 KB | Chernous_dn |
#4 | menu_html_twig_has_an-2501491-4.patch | 1.94 KB | Chernous_dn |
#1 | menu_html_twig_has_an-2501491-1.patch | 1004 bytes | star-szr |
Comments
Comment #1
star-szrCan't resist.
Comment #2
star-szrAdding before/after of compiled Twig templates to the issue summary.
Comment #4
Chernous_dn CreditAttribution: Chernous_dn at FFW for FFW commentedI added some changes to the patch #1 and add closing tags
</ul>
Comment #5
Chernous_dn CreditAttribution: Chernous_dn at FFW for FFW commentedComment #6
joelpittet@Chernous_dn I think @Cottser realized we may still need this... check out if the toolbar still works?
Comment #8
Chernous_dn CreditAttribution: Chernous_dn at FFW for FFW commented@joelpittet Yes, I made a mistake. Update patch.
Comment #9
star-szrOops I thought I closed this. Pretty sure we do need the import :)
Comment #11
star-szrComment #12
Chernous_dn CreditAttribution: Chernous_dn at FFW for FFW commented