This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Setup & design » How to hide one element of a page...
expandshrink

How to hide one element of a page from anonymous users?

How to hide one element of a page from anonymous users?

Saturday 20 October 2012 11:59:37 am - 5 replies

Hi,

I want to add a discount code text field to a template that's hidden from anonymous users.

I'll say in the description that if they register they'll see discount codes so they're more inclined to register.

Please can someone supply the code to go around the field? This below, obviously isn't it...

 

{if $node.object.data_map.discount-code.has_content}

<h3>Discount code</h3>

                {attribute_view_gui attribute=$node.data_map.discount-code}
                <br />

{/if}

 

Many Thanks in advance

Saturday 20 October 2012 1:34:20 pm

Hello Neo Pixel,

One solution will be to test if current user is anonymous :

 {def $current_user = fetch( 'user', 'current_user' )
        $anonymousUserID = ezini( 'UserSettings', 'AnonymousUserID', 'site.ini' )}
{if eq( $current_user.contentobject_id, $anonymousUserID )}
   <h3>Discount code</h3>
   {attribute_view_gui attribute=$node.data_map.discount-code}
{/if}

Sunday 21 October 2012 11:15:44 pm

Hi Paul,

Thanks, I'll give that a try

Sunday 21 October 2012 11:23:50 pm

Erm,

that works except its the wrong way round.

It hides the new textline from registered users and shows it to anonymous ones.

I need it to show when a user is signed in.

Thanks again!

Modified on Sunday 21 October 2012 11:25:01 pm by Neo Pixel

Monday 22 October 2012 11:50:20 am

Oh sorry, this one should work blunk.gif Emoticon

 {def $current_user = fetch( 'user', 'current_user' )
        $anonymousUserID = ezini( 'UserSettings', 'AnonymousUserID', 'site.ini' )}
{if eq( $current_user.contentobject_id, $anonymousUserID )|not}
   <h3>Discount code</h3>
   {attribute_view_gui attribute=$node.data_map.discount-code}
{/if}

Paul

Modified on Monday 22 October 2012 11:51:10 am by Paul FROMAGE

Tuesday 23 October 2012 9:05:18 pm

Works perfectly

 

Thanks big-smile.gif Emoticon

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from