{avatar:image:name:size}

Description

Renders a small square avatar for a person or organisation. Given an image URL it returns an img tag sized to a square thumbnail (width and height both equal to size, aspect ratio ignored). If the image is empty or cannot be loaded it falls back to a coloured div showing the initials taken from the name. The initials are the first letter of the name plus the first letter of the second word, or the second letter if there is only one word; a name containing an @ is treated as an e-mail and only the part before the @ is used for the title and initials. The fallback colour is derived from the name, one of eight CSS classes dis-color1 to dis-color8, so the same name always gets the same colour. Defined in AA_Stringexpand_Avatar in stringexpand.php. Typical use inside an item template is the avatar of an uploaded photo field with the headline as the name, feeding an image field and the _#HEADLINE alias.

Parameters

image optional default (empty)

URL of the image to show. When it resolves to a loadable image the result is a square img thumbnail at the chosen size. When empty or not loadable, avatar falls back to a coloured initials div built from the name.

name optional default (empty)

Person or organisation name. Used for the title attribute and to derive the fallback initials and colour. If it contains an @ it is treated as an e-mail and only the part before the @ is used.

size optional default 48

Square side length in pixels for the image thumbnail. Applied as both width and height. Has no visible effect on the initials fallback.

Examples

test{striptags:{avatar::Jane Doe}}
ExpectedJD
ActualJD
With no image, avatar falls back to a coloured chip with the initials. striptags here keeps only the visible initials so the result is plain text. JD = first letter of each of the two words.
test{striptags:{avatar::Greenpeace}}
ExpectedGr
ActualGr
A single-word name uses its first two letters for the chip. Greenpeace becomes Gr. striptags keeps only the initials text.
test{striptags:{avatar::jane@example.org}}
Expectedja
Actualja
A name containing an @ is treated as an e-mail; only the part before the @ feeds the initials and title. jane@example.org becomes ja.
test[{striptags:{avatar:}}]
Expected[--]
Actual[--]
With neither image nor name, the chip shows the placeholder initials. The name is padded with dashes, so an empty name yields two dashes.
virtual{avatar::Jane Doe}
Expected(a div with class dis-color8, title Jane Doe, and the initials JD; rendered here as a coloured chip)
Actual
JD
The full fallback output without striptags. The colour class is derived from the name so the same name always gets the same colour; the title holds the name. The browser renders this as a coloured chip, which is why this is illustrative rather than an asserted test.
virtual{avatar:{img_url.........}:Maria Lopez}
Expected(an img thumbnail of the photo field, or an initials chip ML from the name)
Actual
ML
The canonical pattern inside an item template feeds a photo field as the image and a name. In your own template you would use the item headline alias for the name. If the photo loads you get an img thumbnail, otherwise the initials chip from the name.
virtual{avatar:https#://example.org/photo.jpg:Alice:64}
Expected(an img tag whose src is the install img.php thumbnail of the URL at 64 by 64 pixels, with title and alt set to Alice)
ActualAlice
When the image loads, avatar returns a square img thumbnail at the given size (both width and height). The colon in the URL is escaped as a hash-colon so it is not read as a parameter separator.