Michaelis Posted January 17 Share Posted January 17 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"> Personnel file</span></a> </li> Quote Link to comment Share on other sites More sharing options...
Administrators Jon Erickson Posted January 22 Administrators Share Posted January 22 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? Quote Owner Deschutes Design Group LLC email | jon@deschutesdesigngroup.com Link to comment Share on other sites More sharing options...
O.Ellis Posted January 22 Share Posted January 22 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"> Personnel file</span></a> </li> {{endif}} {{endforeach}} Quote Link to comment Share on other sites More sharing options...
Administrators Jon Erickson Posted January 22 Administrators Share Posted January 22 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"> 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. 1 Quote Owner Deschutes Design Group LLC email | jon@deschutesdesigngroup.com Link to comment Share on other sites More sharing options...
O.Ellis Posted January 22 Share Posted January 22 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 😄 1 Quote Link to comment Share on other sites More sharing options...
Michaelis Posted January 22 Author Share Posted January 22 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 Quote Link to comment Share on other sites More sharing options...
O.Ellis Posted January 22 Share Posted January 22 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. Quote Link to comment Share on other sites More sharing options...
Michaelis Posted January 22 Author Share Posted January 22 Got it working by adding {{$soldier = \IPS\perscom\Personnel\Soldier::load($member->member_id, 'personnel_member_id');}} to the ProfileHeader! Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.