Tutorials/Hiding elements for non registered user

A common requirement in many shops is to display certain features or elements only to registered users. This can be used to restrict features or benefits to registered users, and to motivate anonymous visitors to sign up and provide their details to the shop owner.

This tutorial discusses one technique to implement this requirement in OXID eShop, using a custom Smarty block plugin.

Step 1: Create the Smarty Plugin
Create the file /core/smarty/plugins/block.oxhideblock.php and fill it with the following code:

Step 2: Use the Smarty Plugin in OXID Page Templates
To see how this works, let's take a simple example: displaying a custom message bar to logged in users. To do this, add the following code to the start page template /out/basic/tpl/start.tpl

Once you save the changes, try accessing the OXID eShop start page before and after logging in. The following figures illustrate the difference:

Logged in:


As illustrated in the previous listing, it is quite easy to use this Smarty plugin in a template file. Simply surround the code block you wish to hide with [{oxhideblock}] ... [{/oxhideblock}] tags, and the block will only be visible to registered users. It's also quite easy to adapt this technique to different uses - for example, displaying certain content only to high-value shoppers - by modifying the business rules inside the Smarty plugin.