Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
theme system
Priority:
Minor
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
10 Nov 2014 at 23:45 UTC
Updated:
5 Dec 2014 at 11:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
wim leersComment #2
tom verhaeghe commentedComment #3
tom verhaeghe commentedAdded new variable 'author_anonymous' and updated twig templates to use that in both the comments module and bartik.
Comment #4
wim leersWouldn't
author_is_anonymousbe better?Comment #5
tom verhaeghe commentedConventionally that would be better, I also didn't update the twig documentation. I'll fix that ...
Comment #6
tom verhaeghe commentedComment #7
wim leersThanks! Looks great.
Comment #8
alexpottCan we not use
comment.getOwner().isAnonymous()in twig instead of a new variable?Comment #9
joelpittet@alexpott Yes we can. We can also use:
comment.owner.anonymous ? 'by-anonymous'or any combo that reads the best.@Tom Verhaeghe what are your thoughts here, any preference?
Comment #10
wim leers#8: oh, I didn't know that was possible, that's even better :)
Comment #11
joelpittetFrom our slides:)
http://drupaltwig.github.io/ThemeSystemBadCamp2014/#/5
The more people that know this magic/syntax sugar the better
Comment #12
wim leers#11: Great, thanks! :) That was very helpful :)
Comment #13
tom verhaeghe commentedChanged the way to check if the author is anonymous.
PS: Is it possible that calling methods on objects is done this way
comment.getOwner().isAnonymous()instead ofcomment->getOwner()->isAnonymous()as shown in the slides?Comment #14
wim leersAssigning to Joël for review.
Comment #15
joelpittet@Tom Verhaeghe sorry our slides could be clearer.
{{ comment.owner.anonymous }}will get converted to PHP eventually. When it does, each "attribute" (the thing after the dot, Twig's language for what we usually refer to as a member variable or property) will be converted to PHP in the following ways:In that order of checking until it finds the correct PHP 'thing'.
In this specific case it will do the following (theory and rough equivalent):
Here's an example of all the things that work:
Then visit
http://localhost/magichttps://gist.github.com/c5a20ddd1621e4d07e88
So I personally recommend the calls without the method calls, though #13 will technically work and is fine:)
Comment #16
joelpittetLong story short, #13 is good as-is and should work beautifully though I'd prefer the slightly simpler syntax.
Comment #17
tom verhaeghe commentedOkay, thanks for explaining. It's clear to me now :-)
I changed the syntax in this patch.
Comment #18
wim leersRTBC per #16.
(That's quite a bit of magic though.)
Comment #19
alexpottReclassifying as a bug since
Sounds like one.
This issue is a minor bug fix, and doesn't include any disruptive changes, and is in the unfrozen category (templates) so it is allowed per https://www.drupal.org/core/beta-changes. Committed 010cfbb and pushed to 8.0.x. Thanks!