heydoon Posted December 14, 2017 Posted December 14, 2017 I'm trying to add group color to the userLink template <a> tag. How can I pass in a variable into the template? It's in core->front->global. Sorry, I'm new to this framework and don't quite know my way around. Is what I'm trying to do a reasonable thing or should I just use {{ }} tags and write my PHP in the template?
newbie LAC Posted December 14, 2017 Posted December 14, 2017 {template="userLink" group="global" app="core" params="$memberObject, null, true"}
heydoon Posted December 14, 2017 Author Posted December 14, 2017 Is it better handle logic in template like this? {{ $split = explode("style='", $member->group['prefix']); }} {{ $s1 = explode("'>",$split[1]); }} {{ $color_style = $s1[0]; }} {{if $member->member_id AND \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'core', 'members' ) ) }}<a style="{$color_style}" href='{{if $warningRef}}{$member->url()->setQueryString( 'wr', $warningRef )}{{else}}{$member->url()}{{endif}}' data-ipsHover data-ipsHover-target='{$member->url()->setQueryString( array( 'do' => 'hovercard', 'wr' => $warningRef, 'referrer' => urlencode( \IPS\Request::i()->url() ) ) )}' title="{lang="view_user_profile" sprintf="$member->name"}" class="ipsType_break">{{if $groupFormatting && $member->group['prefix']}}{$member->group['prefix']|raw}{{endif}}{$member->name}{{if $groupFormatting && $member->group['suffix']}}{$member->group['suffix']|raw}{{endif}}</a>{{else}}{{if $groupFormatting && $member->group['prefix']}}{$member->group['prefix']|raw}{{endif}}{$member->name}{{if $groupFormatting && $member->group['suffix']}}{$member->group['suffix']|raw}{{endif}}{{endif}} Or to do this in a PHP function which passes it into the template? public function link( $warningRef=NULL, $groupFormatting=FALSE ) { if ( !\IPS\Settings::i()->warn_on ) { $warningRef = NULL; } $split = explode("style='", $this->group['prefix']); $s1 = explode("'>",$split[1]); $color = $s1[0]; return \IPS\Theme::i()->getTemplate( 'global', 'core', 'front' )->userLink( $this, $warningRef, $groupFormatting, $color ); } What is better practice & better for if I install an update?
newbie LAC Posted December 14, 2017 Posted December 14, 2017 Better install If you creating the plugin and override the link method your code can be looks like /** * HTML link to profile with hovercard * * @param string|NULL $warningRef The reference key for warnings * @param boolean $groupFormatting Apply the group prefix/suffix to the name? * @return string */ public function link( $warningRef=NULL, $groupFormatting=FALSE ) { $userLink = parent::link $warningRef, $groupFormatting); if ($this->group['prefix']) { // Get style properties from group prefix // $styleProperties = ... $userLink = str_replace('href', "style='{$styleProperties}' href", $userLink); } return $userLink; } If you works with Theme Hook you can use PHP Mode
Recommended Posts
Archived
This topic is now archived and is closed to further replies.