Move Template switch to php file

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
HiFiKabin
Community Team Member
Community Team Member
Posts: 3154
Joined: Wed May 14, 2014 9:10 am
Location: Swearing at the PC, UK
Name: James
Contact:

Move Template switch to php file

Post by HiFiKabin » Sun Mar 11, 2018 5:12 pm

In my Header Links ext I now have permission switches in the template as below.

Code: Select all

{% if (headerlink_urls.HEADERLINK_PERMISSION eq '1' and not S_USER_LOGGED_IN) or (headerlink_urls.HEADERLINK_PERMISSION eq '2' and S_USER_LOGGED_IN) or (headerlink_urls.HEADERLINK_PERMISSION eq '4' and U_ACP) or (headerlink_urls.HEADERLINK_PERMISSION eq '5' and U_MCP) or headerlink_urls.HEADERLINK_PERMISSION eq '3'%}
(allowing each link to have view permissions based on the group the user is in)

How can I move this from the html file to the php one? I have looked around and can not find what I am looking for so any pointers and/or existing extension doing a similar thing will be most welcome.

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3104
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Move Template switch to php file

Post by kasimi » Fri Mar 16, 2018 3:51 pm

Use the value you assign to the template for HEADERLINK_PERMISSION in an if condition, for example:

Code: Select all

if (($url_permission == 1 && $user->data['user_id'] == ANONYMOUS)
	|| ($url_permission == 2 && $user->data['user_id'] != ANONYMOUS)
	|| $url_permission == 3
	|| ($url_permission == 4 && $this->auth->acl_get('a_'))
	|| ($url_permission == 5 && ($this->auth->acl_get('m_') || $this->auth->acl_getf_global('m_')))
)
{
	// call assign_block_vars in here
}

User avatar
HiFiKabin
Community Team Member
Community Team Member
Posts: 3154
Joined: Wed May 14, 2014 9:10 am
Location: Swearing at the PC, UK
Name: James
Contact:

Re: Move Template switch to php file

Post by HiFiKabin » Fri Mar 16, 2018 5:38 pm

Right! Got it (at last) Thanks Jonas, I just could not get that code working correctly, though I was getting lots of errors :lol:

Thats my job for tomorrow :ugeek:

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: ahigh and 11 guests