Search code examples
phpjoomlasmarty

How to insert smarty code tpl file in to tpl file according to user access group


For Joomla 3 currently I am trying to display a tpl file in tpl file for specific user group.

First I tried to create a module position for custom code module with the following code

{php}
echo JHtml::_('content.prepare', '{loadposition companydetail}'); 
{/php}

Module positon works well but there is a problem. The code that i want to use is .tpl file code. So custom code module does not work with it.

Than with smarty codes i have created a .tpl file and called it in to main .tpl file for access group that i created.

{php}
$user_  = JFactory::getUser();
$db     = JFactory::getDBO();
foreach($user_->groups as $group){
$query  = 'SELECT title FROM #__usergroups';
$query .= ' WHERE id = ' . $group;
$db->setQuery( $query );
if ($db->loadResult() == "Business")
{
echo '{include file='companydetail.tpl'}'; 
}
}
{/php}

It is working well until trying to include tpl file. Because code is not smarty. Basicly i need smarty version of this code part.

Tried this but not working

{ 
$user_ = JFactory::getUser(); 
$db = JFactory::getDBO(); 
{foreach $user_->groups as $group} 
$query = 'SELECT title FROM #__usergroups'; 
$query .= ' WHERE id = ' . $group; 
$db->setQuery( $query ); 
{if $db->loadResult() == "Business"} 
{include file='companydetail.tpl'} 
{/if} 
{/foreach} 
}

On some forums people offer to create a class for this but this is not what i want. Anybody can display that part with browser editor.

I hope somebody can help about this. Thanks in advance.

Regards


Solution

  • Here is solution,

    {if in_array('10', $joomlauser->groups)}
    {/if}
    

    10 is id of group. With this code only 10 can see that part of page. It wasn't my solution. I got some help from another forum. Hope this will help to others to.

    Regards