XF 2.1 Need help with handling phrase variable in HTML template

Aivaras

Well-known member
The template "reaction_list" starts with:
HTML:
<xf:if is="$title">
    <xf:title>{$title}</xf:title>
<xf:else />
    <xf:title>{{ phrase('members_who_reacted_to_this') }}</xf:title>
</xf:if>
wherein {$title} retrieves members_who_reacted_to_message_x if the reaction list is opened in Thread view, or members_who_reacted_to_message_by_x if the reaction list is opened in Conversation view.

Now, members_who_reacted_to_message_by_x contains the variable {user} whose initial value I want to replace with that of a custom user field. To achieve this I've come up with the following code:
HTML:
<xf:if is="$title AND $content.Conversation">
    <xf:title>{{ phrase('members_who_reacted_to_message_by_x', {'user': $content.User.Profile.custom_fields.test}) }}</xf:title>
<xf:elseif is="$title" />
    <xf:title>{$title}</xf:title>
<xf:else />
    <xf:title>{{ phrase('members_who_reacted_to_this') }}</xf:title>
</xf:if>
The code works with one exception: opening the reaction list in Thread view triggers a server error logged in ACP as "Accessed unknown getter 'Conversation' on XF:Post[XXX]." This, I assume, is caused by $title AND $content.Conversation when it is parsed in Thread view.

How can I stop the server error from occurring while retaining the functionality of the above code?
 
<xf:if is="$title and $content.Conversation is not empty"> try this and let me know or empty function it doesn't work
 
The $content variable refers to the Entity. I think you can use the instanceof keyword in template conditionals:

HTML:
<xf:if is="$title && $content instanceof 'XF\Entity\ConversationMessage'">
 
That did the trick, Liam! The server error is gone now. Thank you very much for your kind assistance.
 
Top Bottom