Forum Discussion
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:
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...
- 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.
- 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!
- RobbL15 years agoLithium 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.
- Clairekav15 years agoAce
Thanks, I've now cracked it for 'rank'.
It took a little bit of messing around - but the code you need is "user.ranking.id"
To get the ranking ID - go into the User management, edit rank - in the URL you can see the ID number at the end.
So in my example "Newbie giffgaffer" rank = 41.
<#if user.ranking.id = 41 >Welcome to giffgaff <#else>Welcome handy giffgaffer </#if>
Or to include different rankings (this still needs a little more testing, but seems to work OK)
<#if user.ranking.id = 23 >Welcome apprentice giffgaffer</#if> <#if user.ranking.id = 41 >Welcome giffgaff newbie <#else>Welcome handy giffgaffer </#if>
I did try to map to min number of posts, however this is linked to the metric table, which I think makes it too hard and gave up.
Ideally I'd still like to crack this by registration date - if anyone has any suggestions for getting 'less than x date' to work - please let me know.
Related Content
- 2 months ago
- 2 months ago
- 6 months ago
- 11 months ago