Drupal: .htaccess Access Deny
August 21, 2014 – 7:59 am | No Comment

In this article I will tell how to forbid access to certain resources for some clients. The instructions will include descriptions of different directives.

Read the full story »
CSS Templates

Contain reviews and news about CSS Templates.

Freebies

Contain freebies such as icons, graphics, headers and images for your websites.

Fun Stuff

Contains other fun stuff for entertainment or interesting site showcase.

How-To

Contain technical elaborations on some specific workarounds or common tweak.

Joomla Templates

Contains reviews and news about Joomla templates.

Home » How-To

Drupal: How to Hide a Part of an Article from Anonymous Visitors

Submitted by on January 21, 2011 – 10:01 amOne Comment

This article will tell you how to hide a part of an article from anonymous visitors and show it for registered users only. We will do this in a few different methods.

Solutions:

  • Using snippet
  • Filtering of a special tag in theme template
  • Using hidden_text module-filter
  • Using Hidden Content module (http://drupal.org/project/hidden_content)
  • Using Contemplate module (http://drupal.org/project/contemplate)

Using snippet

  • Set format of article output to РНР
  • Insert a code (snippet):

    <?php
    global $user;
    if (is_object($user) and $user->uid>0) {
    ?>
    Registered users only will see this
    <?php
    } else {
    ?>
    <a href=”http://example.com/user”>Get introduced</a> or <a href=”http://example.com/user/register”>Get registered</a>, to read hidden text.
    <?php
    }
    ?>

Filtering of a special tag in theme template

Include hidden text in a node to a special tag.
Get node text in template:

$node=node_load($nid);.
$node=node_prepare($node); //will allow you to generate the filtered content.

Filter a special tag with the help of regular expressions and output different text depending on a user (registered or not).

Using hidden_text module-filter

hidden text filter hides content from anonymous user.  Input format will be non-cached with the filter.

When you include the text between tags [hidden=Text] and [/hidden], it will be visible for registered users only.

If “Text” attribute is set, then specified text “Text” will be shown. Besides, a record of this kind: [hidden title=Text] is allowable for tag [hidden].

Example::

[hidden title=Sign up to view the hidden text]

Hidden text

[/hidden]

You can enter a link to registration page for a title.

Themization

  • title” will be included to span tags with “hidden-text hidded” class
  • Text” will be included to span tags with “hidden-text” class

Using Hidden Content module

You can use Hidden Content module (http://drupal.org/project/hidden_content) to hide a part of an article from unregistered users. You can learn more about it on the Drupal’s official site.

One Comment »

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.