Jump to content

Custom formatting with member field


Meddysong

Recommended Posts

Posted

In one of my Pages database I have a field type set to member. I would like to use some custom formatting when outputting it, such that it looks like this:

OnPaste.20170223-153723.thumb.jpg.f3d4c09299e40829ace77ce9b427e5c9.jpg

The problem is that I can't use the usual $member object which features in other template, because then it would provide the details of the user logged in, not the user reading the record.

I've made some changes using the $formValue, which has got my link going to the correct profile. But I'm lost in other parts of the code because it involves properties of the $member object. (I might be using the wrong words there. I'm afraid I'm a novice. I mean things like $member->$name.)

Presumably there's some way of getting $formValue in there, is there, so that it's $member($formValue)->$name or something like that. But I haven't a clue what to do, even if I understand the basic problem.

Would anybody be kind enough to give me some pointers about what to change in this, please?

{{if $formValue}}
<a class="ipsButton ipsButton_veryLarge ipsButton_normal" href='{url="app=core&module=members&controller=profile&id={$formValue}"}' title="{lang="view_user_profile" sprintf="$member->name"}">{lang="view_user_profile" sprintf="$member->name"}</a>
{{endif}}

 

Posted

It's not ideal but seeing as the record title is also the person's name, I used that:

{{if $formValue}}
<div class="ipsType_center">
  <a class="ipsButton ipsButton_veryLarge ipsButton_normal" href='{url="app=core&module=members&controller=profile&id={$formValue}"}' data-ipsTooltip title="{lang="view_user_profile" sprintf="$record->_title"}">{lang="view_user_profile" sprintf="$record->_title"}</a>
{{endif}}
{{if $formValue}}
	<a href='{url="app=core&module=messaging&controller=messenger&do=compose&to={$formValue}" seoTemplate="messenger_compose"}' ata-ipsTooltip data-ipsDialog data-ipsDialog-title='{lang="compose_new"}' data-ipsDialog-remoteSubmit data-ipsDialog-flashMessage="{lang="message_sent"}" class='ipsButton ipsButton_veryLarge ipsButton_alternate'><i class='fa fa-envelope'></i> <span class='ipsResponsive_showDesktop ipsResponsive_inline'>  {lang="message_send"}</span></a>
{{endif}}
</div>

 

Posted
3 hours ago, Meddysong said:

It's not ideal but seeing as the record title is also the person's name, I used that:


{{if $formValue}}
<div class="ipsType_center">
  <a class="ipsButton ipsButton_veryLarge ipsButton_normal" href='{url="app=core&module=members&controller=profile&id={$formValue}"}' data-ipsTooltip title="{lang="view_user_profile" sprintf="$record->_title"}">{lang="view_user_profile" sprintf="$record->_title"}</a>
{{endif}}
{{if $formValue}}
	<a href='{url="app=core&module=messaging&controller=messenger&do=compose&to={$formValue}" seoTemplate="messenger_compose"}' ata-ipsTooltip data-ipsDialog data-ipsDialog-title='{lang="compose_new"}' data-ipsDialog-remoteSubmit data-ipsDialog-flashMessage="{lang="message_sent"}" class='ipsButton ipsButton_veryLarge ipsButton_alternate'><i class='fa fa-envelope'></i> <span class='ipsResponsive_showDesktop ipsResponsive_inline'>  {lang="message_send"}</span></a>
{{endif}}
</div>

 

I see you're on the right track, however I wouldn't use it as a field item. Use the code directly to your Records Display (record) to display the item. 

<a class="ipsButton ipsButton_veryLarge ipsButton_normal" href='{url="app=core&module=members&controller=profile&id={$record->author()->member_id}"}' title="{lang="view_user_profile" sprintf="$record->author()->name"}">{lang="view_user_profile" sprintf="$record->author()->name"}</a>
{{if \IPS\Member::loggedIn()->member_id && !$record->author()->members_disable_pm and !\IPS\Member::loggedIn()->members_disable_pm and \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'core', 'messaging' ) )}}
	<a href='{url="app=core&module=messaging&controller=messenger&do=compose&to={$record->author()->member_id}" seoTemplate="messenger_compose"}' data-ipsDialog data-ipsDialog-title='{lang="compose_new"}' data-ipsDialog-remoteSubmit data-ipsDialog-flashMessage="{lang="message_sent"}" class='ipsButton ipsButton_primary'><i class='fa fa-envelope'></i> <span class='ipsResponsive_showDesktop ipsResponsive_inline'>&nbsp; {lang="message_send"}</span></a>
{{endif}}

Changing $member->name to $record->author()->name. and used member_id gets user id number

anything with $member can be translated to $record->author()->(what ever classname you want to use) This will only work if you are the person who created the topic.

Some classnames you can find in the Profile / ProfileHeader template inside your Themes 

Not all classnames will work with pages. You just have to play with it (trial and error).

same goes for your listing template instead of $record-> change to $row-> will work as well  

Hopefully this will help you :D

Posted

That's handy, thank you. As it happens, I create the articles but indicate the relevant people as the author so that they can edit it later, so your work-around will work.

Thank you, too, for the extra code about only showing the message button if the member is logged in and the author hasn't disabled messaging. I thought I was going to have to create a Yes/No field about whether the author wanted messaging enabled and then build that into the template, so you've saved me a lot of trouble. Thanks!

Posted

Ah, no - change of plan. The username of the record author isn't necessarily the person's name. This is quite formal, so it needs to read "Go to John Smith's profile" rather than "Go to Meddysong's profile". But that snippet of code about messaging will still come in useful, though :)

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...