1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Conditional Help Needed Message Template and Usergroups

Discussion in 'XenForo Questions and Support' started by Michael, Mar 2, 2013.

  1. Michael

    Michael Active Member

    Hey I am trying to display some content for members of one usergroup within the message template, I am trying to use this but it doesnt appear to work:

    <xen:if is="{xen:helper ismemberof, $user, 4}">
    <xen:if is="{$message.customFields.my_test}">
    <p>{$message.customFields.my_test}</p>
    </xen:if>
    </xen:if>

    This seems to work fine within the message_user_info template, any ideas?

    Thank you :)
     
  2. Lawrence

    Lawrence Well-Known Member

    $message and $user are mapped in the message template, so it should work.

    This outputs the fieldId of my selection, so custom data is there:
    {$message.customFields.iwdrp_race.fieldId}

    Try this:
    Code:
    <xen:if is="{$message.customFields.my_test.fieldId}">
    </xen:if>
     
    Michael likes this.
  3. Michael

    Michael Active Member

    Thanks Lawrence, do I need to replace the fieldId part too? I havent tested it just yet but will now regardless :)
     
  4. Michael

    Michael Active Member

    Thanks Lawrence, that appears to output only the first character that the user has entered, without fieldId it works as it should, it seems the usergroup part is incorrect, I am adding myself to the usergroup, filling my field but it is only outputting it when I dont use the usergroup conditional. Any ideas on how to fix that? That conditional for the usergroup works perfectly fine in message_user_info but not message.

    Thank you.
     
  5. Lawrence

    Lawrence Well-Known Member

    Try $visitor in replace of $user for your conditional.

    I only tested this with a radio option choice, and needed the fieldId to make it work, that may be the reason why you do not need the fieldId?
     
    Michael likes this.
  6. Michael

    Michael Active Member

    Visitor isnt working either :( That sounds right yeah this is just a user filled in field.
     
  7. Lawrence

    Lawrence Well-Known Member

    <xen:if is="{xen:helper ismemberof, $visitor, 4}">
    Hello
    </xen:if>

    The above worked for me in message template. Be sure you place it in the right styles message template, :)
     
    Shelley and Michael like this.
  8. Michael

    Michael Active Member

    Does it work for you when you have it around a field so the field will only display for those in the group but show to all?
     
  9. Lawrence

    Lawrence Well-Known Member

    I'm not sure what you mean, can you give an example?
     
    Michael likes this.
  10. Michael

    Michael Active Member

    I have tried both of these:

    Code:
    <xen:if is="{xen:helper ismemberof, $user, 4}">
    <xen:if is="{$message.customFields.my_test}">
    <p>{$message.customFields.my_test}</p>
    </xen:if>
    </xen:if>
    and


    Code:
    <xen:if is="{xen:helper ismemberof, $visitor, 4}">
    <xen:if is="{$message.customFields.my_test}">
    <p>{$message.customFields.my_test}</p>
    </xen:if>
    </xen:if>
    but they only show/work as they should with this removed:

    Code:
    <xen:if is="{xen:helper ismemberof, $visitor, 4}">
     
    </xen:if>
    I am part of the usergroup too so it should show the output to me in the message.

    :)
     
  11. Lawrence

    Lawrence Well-Known Member

    <xen:if is="{xen:helper ismemberof, $visitor, 4}">
    <xen:if is="{$message.customFields.iwdrp_race.fieldId}">
    <p>Slavik likes lime</p>
    </xen:if>
    </xen:if>

    This works in message template. The issue you are having is displaying the actual data. It depends on the input fields: text fields, multiple select units, radio units, etc.
     
    Michael likes this.
  12. Michael

    Michael Active Member

    I am using a text field with a 35 character limit if that helps :D
     
  13. Lawrence

    Lawrence Well-Known Member

    I don't use custom fields, I only have them to develop my roster add-on, and that data is handled by php and sent to a custom template. If you can wait until tomorrow, I'll look more closely into it, and get it to display in the message template.
     
    Shelley and Michael like this.
  14. Michael

    Michael Active Member

    Thanks Lawrence that is perfectly fine for me as this can wait :)
     
  15. Ingenious

    Ingenious Well-Known Member

    I'm not sure exactly what you are trying to do, but if you are trying to display the contents of a custom field, only to a certain usergroup and only if the field is filled in, this works on my forum (in this example, displaying "latitude_member_map" to admin group 3).

    Code:
    <xen:if is="{xen:helper ismemberof, $visitor, 3}">
    <xen:if is="{$visitor.customFields.latitude_member_map}">
    <p>{$visitor.customFields.latitude_member_map}</p>
    </xen:if>
    </xen:if>
     
    Michael likes this.
  16. Michael

    Michael Active Member

    Thank you, what I am wanting is this:

    Bob fills in his computer information in his Personal Details as: Asus Motherboard, 6GB RAM. Bob is a premium member in usergroup 4 and can therefore have this display in the message template to himself and others. Ralph on the other hand is not a premium member, he has the field filled in from his last subscription, he can see Bobs custom field but his own does not display to anyone, when Ralph is moved into usergroup 4 it begins to show again. All other members can see when someone in usergroup 4 has filled theirs in.

    In other words, I want the field to show in the message template only when members are in group 4 which is an additional usergroup but show to everyone the output when the particular member is in group 4.

    I hope thats clearer for what I am wanting to do, it sounds more complicated like that :D
     
  17. Ingenious

    Ingenious Well-Known Member

    I understand. My example just displays the logged in user's custom field data to himself.

    Does my code work if you change all the $visitor to $user? (So it's similar to your OP but replacing $message with $user).
     
    Michael likes this.
  18. Michael

    Michael Active Member

    It doesnt work with all of it changed to user, is that working for you?
     
  19. Ingenious

    Ingenious Well-Known Member

    Yes - but only in certain places, where $user would be available. For example, it works to show under the username (under the avatar next to a post) in the message_user_info template, a custom field value for that user only if they are a member of that specific group and the field is filled in.

    I tried it elsewhere for example under a post but it was blank so I assumed in that part of the template the $user value is not available, in other words that part of the template was outside of whatever loop was dealing with displaying data specific to a user.

    Hope that makes sense, so yes it does work in some places and I have confirmed this on my own forum. That's about the limits of my knowledge here, sorry.
     
    Michael likes this.
  20. Michael

    Michael Active Member

    Thank you, it seems like I cannot use it where I need it, I need it before or after the signature in the message template :D
     

Share This Page