Page 1 of 1

Problems with OR - AND in navigation after upgrade to 2.2.1

Posted: Sat Jul 08, 2017 1:39 pm
by raiyul
On a page I had this code :

Code: Select all

{if feu_smarty::is_user_memberof('Auteurs,Membres,potentiel')}
I choose this page page
 {Navigator template="nautres.tpl"}
{else}
You must be member
 {/if}
and the content of template nautres.tpl was

Code: Select all

{if !isset($depth)}{$depth=0}{/if}
{if isset($nodes)}{strip}
<ul style="list-style-type:none; ">
{foreach $nodes as $node} 
{if ($node->extra1 == 'retour' ) or ($node->extra1== 'annonce') or 
(   ($node->extra1=='membres'and feu_smarty::is_user_memberof('Membres')) or
    ($node->extra1=='auteurs'and feu_smarty::is_user_memberof('Auteurs'))or 
    ($node->extra1=='attente'and feu_smarty::is_user_memberof('potentiel'))
	 )}
  {if $node->current}
  <li><a href="{$node->url}" class="currentpage"{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext} </a>
  {else}
  <li><a href="{$node->url}">{$node->menutext}</a></li>
  {/if}
{/if}
{/foreach}
</ul>
{/strip}{/if}
After upgrade from 2.1.5 to 2.2.1 open this page gave this error :
Syntax error in template "module_file_tpl:module_file_tpl:Navigator;nautres.tpl" on line 19 "( ($node->extra1=='membres'and feu_smarty::is_user_memberof('Membres')) or" - Unexpected "and"
I could remove all AND by using more IF conditions and it was OK for this page.
But I had a new error in a gabarit with the code :

Code: Select all

{menu template="autres.tpl"}
and the content of template autres.tpl was

Code: Select all

<ul style="list-style-type:none; ">
{foreach from=$nodelist item=node} 
{if ($node->extra1 == 'retour' ) or ($node->extra1== 'annonce') or 
(  ($ccuser->loggedin())and 
   (($node->extra1=='membres'and feu_smarty::is_user_memberof('Membres')) or
    ($node->extra1=='auteurs'and feu_smarty::is_user_memberof('Auteurs'))or 
    ($node->extra1=='attente'and feu_smarty::is_user_memberof('potentiel'))
	))}
  {if $node->current == true}
  <li><a href="{$node->url}" class="currentpage"{if $node->target ne ""} target="{$node->target}"{/if}> {$node->Syntax error in template "module_file_tpl:module_file_tpl:MenuManager;autres.tpl"  on line 4 "(  ($ccuser->loggedin())and"  - Unexpected "and"
menutext} </a>
  {else}
  <li><a href="{$node->url}">{$node->menutext}</a></li>
  {/if}
{/if}
{/foreach}
</ul>
and here, came this error explanation :
Syntax error in template "module_file_tpl:module_file_tpl:MenuManager;autres.tpl" on line 4 "( ($ccuser->loggedin())and" - Unexpected "and"
At this point, I changed all AND in && and all OR in || and since I made these changes in both templates, my site runs perfectly.

I presume that navigation with templates containing so much AND - OR are harder to compile than with && - || instead.

Re: Problems with OR - AND in navigation after upgrade to 2.

Posted: Sat Jul 08, 2017 2:50 pm
by calguy1000
CMSMS 2.2 introduced a newer version of smarty that probably has tougher parsing rules.

The words 'or' and 'and' are permitted operators in exchange for '||' and '&&' respectively. I think the problem you are having here is with whitespace. The lexer/parser is probably having a problem understanding that the 'or' is intended as an operator. I would add whitespace around all of your comparison operators.

Code: Select all

($node->extra1=='auteurs'and feu_smarty::is_user_memberof('Auteurs'))or

Re: Problems with OR - AND in navigation after upgrade to 2.

Posted: Sat Jul 08, 2017 3:49 pm
by raiyul
With whitespace around all of your comparison operators it's OK.
Many thanks for the answer

Re: Problems with OR - AND in navigation after upgrade to 2.

Posted: Sat Jul 08, 2017 6:08 pm
by calguy1000
As an added note: FEU can take care of 90% of that automatically now.

Change the content type to 'Protected content' and then set the allowed group(s) when editing the page.