Jump to content

Forums

Button/Link t personnel file on forum profile?


Michaelis
 Share

Recommended Posts

Hey there, i'm trying to figure out how I can create an button linked to a members personnel file.
I have the button but now i need to figure out how to link <a href= to the personnel file, the following code is not working and returns with an error on the profile page:
 

<li>
  <a href='{$soldier->url()}' class="ipsButton ipsButton_primary"><i class="fa fa-id-card"></i><span class="ipsResponsive_showDesktop ipsResponsive_inline">&nbsp; Personnel file</span></a>
</li>

 

Link to comment
Share on other sites

One way to achieve this outside of the soldier profile is 

 

{{$soldiers = \IPS\perscom\Personnel\Soldier::roots();}} 
  {{foreach $soldiers as $soldier}} <!-- Loops through every soldier-->
    {{if $soldier->member_id === $member->member_id}} <!-- Locates the Soldier who has the same ID as the profile-->
      <li>
        <a href='{$soldier->url()}' class="ipsButton ipsButton_primary"><i class="fa fa-id-card"></i><span class="ipsResponsive_showDesktop ipsResponsive_inline">&nbsp; Personnel file</span></a>
      </li>
    {{endif}}
  {{endforeach}}

 

Link to comment
Share on other sites

  • Administrators
Just now, O.Ellis said:

One way to achieve this outside of the soldier profile is 

 

{{$soldiers = \IPS\perscom\Personnel\Soldier::roots();}} 
  {{foreach $soldiers as $soldier}} <!-- Loops through every soldier-->
    {{if $soldier->member_id === $member->member_id}} <!-- Locates the Soldier who has the same ID as the profile-->
      <li>
        <a href='{$soldier->url()}' class="ipsButton ipsButton_primary"><i class="fa fa-id-card"></i><span class="ipsResponsive_showDesktop ipsResponsive_inline">&nbsp; Personnel file</span></a>
      </li>
    {{endif}}
  {{endforeach}}

 

Instead of looping through every soldier every time, you can find a soldier by using the member_id. 

\IPS\perscom\Personnel\Soldier::load($member->member_id, ‘member_id’);

or calling isSoldier()

$member->isSoldier();

That will return the soldier object as well if it exists or null if not. 

  • Thanks 1

Owner
Deschutes Design Group LLC
email | jon@deschutesdesigngroup.com

Link to comment
Share on other sites

2 minutes ago, Jon Erickson said:

Instead of looping through every soldier every time, you can find a soldier by using the member_id. 

\IPS\perscom\Personnel\Soldier::load($member->member_id, ‘member_id’);

or calling isSoldier()

$member->isSoldier();

That will return the soldier object as well if it exists or null if not. 


This is a much simplified way of doing it, and will save a lot of time 😄

  • Haha 1
Link to comment
Share on other sites

17 minutes ago, Jon Erickson said:

Calling url() returns a URL object. You must convert it to a string by adding url()->__toString().

Also, where is this code located? Is the $soldier variable available for consumption?

The code would be on the invision profile, not of the perscom profile, so therefore i think it can't call $soldier

 

Link to comment
Share on other sites

47 minutes ago, Michaelis said:

The code would be on the invision profile, not of the perscom profile, so therefore i think it can't call $soldier

 

You can call $soldier using this
 

{{$soldier = \IPS\perscom\Personnel\Soldier::load($member->member_id, 'personnel_member_id');}}

This will search and compare all your soldiers' personnel_member_id against the ID displayed in the profile url, once it identifies the matching soldier, it'll then call $soldier for that soldier.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.