0

I have a view that displays a list of items. How to make anonymous user see this list of items but when accessing the node, it has to be logged? Any idea?

I use the latest version of drupal

1

You can disable node_access check for the view (Edit the View → Advanced → Query settings → Disable SQL Rewriting).

-1

you can also create a page and embed your view inside it. in this way users can see your view. also create a node page and check this condition

if($logged_in)
{
    //your code
 }
  • Hi, Mohammad I'm finally using what you say. But how to make if the user is authenticated not show me the rest of the node and show me another page? – Jansel Oct 15 '13 at 12:57
  • Hi, I could not understand you, if the user is authenticated then your page in the bracket will be displayed. now this is my question: what is the rest of the node and what is another page? please clarify your question then I`ll be able to help you. – No one Oct 15 '13 at 20:09
-1

in order to create a page for your view, I guess your view has a page display, set a path for it, say /test . now create a .php file and name it page--test.tpl.php and embed your view using this instruction :

views_embed_view('NAME_OF_YOUR_VIEW','page');

clear the cache and go to /test you will see your view.

and about your node page, there are couple of things you need to do, first in your template file add this function

function YourThemeName_preprocess_page(&$variables)
{

    if (isset($variables['node'])) 
    {
         if($variables['node']->type == "YourContentTypeName")
         {
                $suggest = "page__node__test";
                $variables['theme_hook_suggestions'][] = $suggest;
         }

    }
}

now create a .php file and rename it to page--node--test.tpl.php, this will be your node page and you can set authentication condition for it. you can even go further and check this authentication condition in your preprocess function, I mean create two different $suggests in preprocess function :

function YourThemeName_preprocess_page(&$variables)
{

    if (isset($variables['node'])) 
    {
         if($variables['node']->type == "YourContentTypeName")
         {
                if($logged_in)
                {
                    $suggest = "page__node__test_authenticated";
                    $variables['theme_hook_suggestions'][] = $suggest;
                }
                else
                {
                        $suggest ="page__node__test_notAuthenticated";
                        $variables['theme_hook_suggestions'][] = $suggest;
                }

         }

    }
}

and now create two node pages in the same way I said, one for authenticated and one for non-Authenticated users. you can also get and set fields of your content type fields in preprocess function and display them in node page. don't forget to clear the chache

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.