Substitution of User Pics?
Nov. 10th, 2008 10:23 am(Probably only of interest to
camomiletea,
scaryjeff,
afuna, or anyone else in Styles support)
There was a recent request about substituting a user's default userpic for the one they'd selected for a particular post. We figured it was possible through S2, but we don't give that level of detail through Support. I found out something interesting while trying to figure it out for myself...
The S2 Core stores the entry user icon in
Maybe
afuna or someone who knows the back-end better knows why, but I guess you can't re-cast a
![[livejournal.com profile]](https://www.dreamwidth.org/img/external/lj-userinfo.gif)
![[livejournal.com profile]](https://www.dreamwidth.org/img/external/lj-userinfo.gif)
![[livejournal.com profile]](https://www.dreamwidth.org/img/external/lj-userinfo.gif)
There was a recent request about substituting a user's default userpic for the one they'd selected for a particular post. We figured it was possible through S2, but we don't give that level of detail through Support. I found out something interesting while trying to figure it out for myself...
The S2 Core stores the entry user icon in
$userpic
, an Image member of the EntryLite
class (usually called in print_entry()
like $e.userpic.url
). A user's default icon is stored in the User
class, which is derived from UserLite
. EntryLite
class also contains a UserLite
object called $poster
, the author of the entry. Since Expressive (unlike other layouts) passes the EntryLite
object into print_entry()
directly, I thought I could get away with something like this:
var User u = $e.poster as User;
var Image def_pic = $u.default_pic;
var string userpic = ($showuserpic and defined $e.userpic) ? ($def_pic + "<br />") : "";
It compiles, but it doesn't work, it just comes up with an empty string. Even trying to isolate the Image members doesn't work:var string pic_url = """<img src="$def_pic.url" alt="$e.userpic.alttext" title="$e.poster.name" height="$def_pic.height" width="$def_pic.width" />""";
Maybe
![[livejournal.com profile]](https://www.dreamwidth.org/img/external/lj-userinfo.gif)
UserLite
object like you can an EntryLite
(print_entry()
in Expressive re-casts the EntryLite
argument into a Comment or Entry object, depending on the type). Even if the preceding were possible, this approach wouldn't work in most layers anyway, because they call print_entry()
on Entry
objects.