Forum Discussion

Clairekav's avatar
15 years ago

Configuring 'Announcement' to display different messages

Hi, I was wondering if it is possible to change the text that is displayed to users according to their registration date (or some other variable that's in the lithium user database)? 

 

We're got lot of new members coming on board at the moment - in the 'Announcement' section on each board I'd like to display a selection of "FAQs" to new members (ie welcome, link to guidelines, how to join etc"), and a different set of FAQ's for members who've been around for a while. 

 

We've got a simple CMS / Java (?) code in the announcement section which displays: 

- If you're not logged in (user anonymous) displays image 1 with link to "join page"

- If you are logged in it displays image 2, linked to the "purchase page"

 

Ideally - I'd like to be able to add some code that looks at their registration date as well i.e.

- if you're logged in and registered < 2 weeks ago you're displayed 'new joiner text'

- if you're logged in and registered > 2 weeks ago, you've displayed another set of text

 

 

Is this possible? Or am I being a little ambitious? (I'm an HTML code / tech novice - I'm looking at this from a CRM Marketing point of view) 

 

Any advice is greatly appreciated - thanks!

 

 

Code we're using at the moment which displays different images according to whether you're logged in or not:

 

 

<#if user.anonymous == true>
<a href="https://ourwebsite/1"> <img src="http://Image1.jpg"> </a>
<#else>
<a href="https://ourwebsite/2" target="_blank"> <img src="http://Image2.jpg"> </a>
</#if>

 

I imagine if it is possible the code would be something like: 

 

<#if user.Registration_time <LESS_THAN>  TodaysDate(-14)>

<p>this text for newbies</p>

<#else>

<p>this other text for older members</p>

</#if>

 

 

  • MoniqueL's avatar
    MoniqueL
    Lithium Alumni (Retired)

    Hi ClaireKav,

     

    I realized you asked this a long time ago, and other users may have had similar situations and found a solution to, I thought I would post mine since this topic post came up when I was looking for an answer to my question :)

     

    I wanted to build a component that you've outlined the logic to here;


     

    <#if user.Registration_time <LESS_THAN>  TodaysDate(-14)>

    <p>this text for newbies</p>

    <#else>

    <p>this other text for older members</p>

    </#if>

     

     


    The amazing AdamN and wonderful KaelaC Helped me craft the following;

     

    By using rest to get the number of user logins here: http://community.lithium.com/t5/Community-API/bd-p/developers-rest-api?leaf-id=User.logins.count#User.logins.count

     

    And using the freemaker expression to write out less than or equal to ( lte) or alternativly, greather than or equal to (gte), I wrote the following component to show a link to all anon users, and logged in users, but only if they've logged in 5 times or less:

     

    <#if user.anonymous>
    	<a href="#">This is my newbie link</a>
    <#else>	
    	<#assign loginCount = rest("/users/id/${user.id}/logins/count").value />
    	<#if loginCount?number lte 5 >
    		<a href="#">This is my newbie link</a>
    	</#if>
    </#if>

    I think is preferable than tying it to a rank, since I'm not a Community Manager, and I dont know how long or what the criteria is to move beyond a rank (plus that could change over time) and I think its better than using a set number of days from register, as I could have registered months ago, but only rememebred to login and check out the community a month from then, where I would be as unfamilar with the community as I was 14 days ago.

     

    So WAY after the fact, but hopfully it can help someone else :catvery-happy:

     

  • AdamN's avatar
    AdamN
    Khoros Oracle

    Hi Clairekav,

     

    Unfortunately I don't have a full solution for you, but I want to throw out some tips that might help get you going in the right direction.

     

    There is a method for the user context object:

    ${user.registrationTime}

    There is also a method for getting a date, for example:

    ${datesupport.now.addDay(-14)}

    However, manipulating and comparing date strings via freemarker might be a little tricky, and it's definitely outside my realm of expertise.

     

    You can find more information about these methods and others here:

    http://lithosphere.lithium.com/t5/Everything-Studio-Knowledge-Base/Writing-custom-components-in-Lithium-Studio/ta-p/9217

    And here's a resource talking about dates in Freemarker:

    http://freemarker.sourceforge.net/docs/ref_builtins_date.html#ref_builtin_string_for_date

     

    Some possible alternatives...

    1. Ranks: If you want to show it to members of a certain rank (ie. New Member), there are REST calls for getting the rank of a user.
    2. Roles: Similarly, if you grant a certain role after users reach a certain rank, you could show the announcement to users that didn't have that role (or vice-versa if you have a "New Member" role that gets removed eventually). There are REST calls to get the roles for a user also.

    Depending on how your rank structure is setup, that might be the easiest approach. If you need more information on the two alternatives, just let me know.

     

    I hope this helps!

     

     

    • Thanks very much for the links AdamN, there is a lot of good info there - I would have never found it on my own! 

       

      After some playing around I've managed to get the text to change based on user.ID and maybe user.registrationTime (?!).

       

      Note if you're trying to use "less than",  < doesn't work, as it interprets this as the end of the code, to you have to use \lt (link here to FreeMarker comparison for further info)

       

      So.....

      I can get varying text according to user ID:

      My ID is 523, so this works: 

       

      <#if user.id == 523 > This is user 523</p>
      <#else>This is another user
      </#if>

       This is less than (using \lt) user ID of 1000:

       

       

      <#if user.id \lt 1000 > This is less than user ID 1000</p>
      <#else>This great than user ID 1000
      </#if>

       

       

      And registration date if exactly 14 days ago - it doesn't throw up an error, however.... 

       

      Date (-14) formula untested: It doesn't seem to change if I put my exact registration date in days ago but it may have something to do with date formatting? 

       

      <#if user.registrationTime == datesupport.now.addDay(-14)> 14 days ago 
      <#else>not 14 days ago
      </#if>

       

      However I'm having trouble with inserting  "less than"  - it throws up big yellow "free marker" error...

       

      <#if user.registrationTime \lt datesupport.now.addDay(14)><p>Mouse found</p>
      <#else><p> not mouse found</p>
      </#if>

       

       

      Any ideas about how to get "less than x days ago" for my "user.registrationTime" variable? 

       

       

       

      If I can't get user.registrationTime to work, I was thinking as AdamN suggested, perhaps using Ranks - however I'm not sure what the variable is called as it wasn't listed under the user info

       

      "user.rank" isn't recognised.... I'm sure it's called something else, I just took a stab. Any clues as to what it is actually called? 

       

       

      <#if user.rank == newbie_giffgaffer > This is a newbie</p>
      <#else>This is an older member
      </#if>

       

      This is quite exciting - I will be great to have variable FAQ's according to join date, rank or even the number of log ins.

       

      Our community base is kind of 'un-traditional' - as we have a lot of people visiting who've never used a forum before - so it will be great to crack this to make things a little easier for them.

       

      Any help is greatly appreciated! 

       

      • RobbL's avatar
        RobbL
        Lithium Alumni (Retired)

        This is the long way around, but here are two ways to get at least some of the variable names. I am making the leap of faith that FreeMarker uses these. If you go into the admin, click on User Management, and either Edit an existing rank or Create a new one, then scroll down to the entry box for Ranking Forumla. If you click the Help Button you will see a pretty good list of variable names.

         

        If the one you want is not there, you can also go to Metrics and likely then Advanced Metrics. If for instance you chose a Report Scope of Role, then picked a role from the list of existing roles in your community, and then any metric on the right, and finally clicked Generate Report, you will see the variable for getting a role - "role.id=" as well as the particular role id both in the URL, as well as in the heading on top of the chart. You can use this method to see the variable name for any of the metrics listed.

         

        I said it was the long way around, and that is likely an understatement. But give those methods a try and let us know.

         

  • I doubt the platform allows this, but it's an awesome idea that you should post to the Idea Exchange!