Log in

View Full Version : Checking for notice being shown


Jon12345
03-29-2012, 02:19 PM
I have about 4 different notices that display according to certain conditions. e.g. Guest Message, Never Posted etc.

Is it possible to test that a particular notice is being shown on a page the user is on, so I can then run some code in the header?

pseudo code:

if noticeshown=Guest Message then

\\ run this code

end if

Thanks,

Jon

kh99
03-29-2012, 03:26 PM
If the notices you want to check are not marked "persistent" then you can check for the id in the array $vbulletin->np_notices_displayed like:

<if condition="!empty($vbulletin->np_notices_displayed[3])">
Notice 3 displayed<br />
</if>


That doesn't work for persistent notices. Also, the ids aren't really displayed anywhere but you can see them in the url (if your browser displays it when you hover over a link) by going to the Notice manage and hovering over the notice name.


It might be a better idea (depending on exactly what you want to do of course) to check the conditions yourself. For instance, if a notice is guests only you could check for <if condition="!$show['member']">.

Jon12345
03-30-2012, 01:55 PM
Alas, they are persistent notices, so maybe your alternative idea might be the better option. What does $show['member'] actually mean?

kh99
03-30-2012, 07:25 PM
$show['member'] gets set to true if a member is logged in, and it'll be false if it's a guest viewing the page. So you can use it in a template condition to change what guests see vs. members.

That probably is a better way to go in general, unless you actually wanted to know if the notice was displayed or not (as opposed to whether or not the user is a guest). But I think if the notice is persistent it amounts to the same thing (oh..ah, unless it's dismissible).