Jump to content

Passing an IPS "shortcut" variable to a template / CSS


Linguica

Recommended Posts

Posted

I wanted to add in a thing to make every user see quotes of themselves in a different color so it was more immediately noticeable. The obvious way to do this was to add a customized CSS rule to every user's CSS that would be processed by the templating engine. However, it doesn't seem that the available shortcuts can be inserted into a template by their actual variable, just as part of the HTML logic if-else or foreach or whatever.

Trying to insert {member.member_id} resulted in that literal text being inserted, and trying {$member.member_id} gave an error.

I managed to get around this by immediately assigning the shortcut variable I cared about to a *second* variable inside of a pointless logic check and then inserting that one, which worked well enough:

{{if member.member_id}}
	[data-ipsquote-userid="{{if $id = member.member_id}}{$id}{{endif}}"]{ 
		background: #173747;
	}
{{endif}}

This seems pretty messy and hacky to me though, and I am just wondering if I overlooked something and there is a more straightforward way of doing this.

Posted

Doesn't work.

58c2366c254c0_ScreenShot2017-03-09at9_14_58PM.png.224d672d230cc9907af47b797fba7724.png

Which is kind of funny, since it clearly *does* work if you use a hacky way of accessing it... but now I am wondering if I am subtly breaking something by doing this.

Posted

And a quick test shows that my suspicion was correct: if you do that hack to put a member-specific variable into a CSS file, and then the user logs out, the guest user will still see the original user's posts highlighted for as long as the CSS is locally cached.

I guess I'll just inline it in the HTML head:

{{if member.member_id}}<style>[data-ipsquote-userid="{member="member_id"}"]{ background: #173747; }</style>{{endif}}

I guess this goes to show that just because you can do something doesn't mean that you should :whistle:

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...