Drupal: How to Hide a Part of an Article from Anonymous Visitors
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.
on my site i use you technique and its just worked thanks.