How do display different content for visitors vs. logged in developers

anton
New Member

Hello,

I'd like to add Register / Login buttons on the main home page but display them only when developers are not logged in, exactly how it works with the Register / Login link on the toolbar.

Thanks in advance,

Anton.

Solved Solved
0 2 103
1 ACCEPTED SOLUTION

@Anton+Bar , I believe your content is a HTML code.

Take a look at this article here which explains how to create custom blocks using module & enable them using context. If you have used custom_home blocks module attached in above article, It's taken care in the template. See custom_home_block2.tpl.php file that renders block 2 based on logged in user or not inside module template folder. See code below of same file.

<div>
    <div>
        <h1>APIs. APPs. Innovation</h1>
        <div>
            We are committed to work together to build <strong>Innovation</strong>, <strong>Apps</strong> and Developer communities. Driven by passion to innovate, We bring our services to you using <strong>APIs</strong>.
        </div>
        <?php
            global $user;
            if ($user->uid== 0) {
                ?>
                <div>
            <span>
                <span>
                    <a href="https://community.apigee.com/user/register">Join Now</a>
                </span>
            </span>
                    <span>
                <span>
                    <a href="https://community.apigee.com/user/login">Sign In</a>
                </span>
            </span>
                </div>
                <?php
            } else {
                ?>
                <div>
            <span>
                <span>
                    <a href="https://community.apigee.com/user/me/apps">My Apps</a>
                </span>
            </span>
                    <span>
                <span>
                    <a href="https://community.apigee.com/user">Profile</a>
                </span>
            </span>
                </div>
        <?php
            }
        ?>
    </div>
</div>

Also, If you don't want to put the code in a custom module & worry about drupal modules stuff. Easier way is to leverage the add block capability in out of the box CMS. See how to do same quickly below.

  • Login as Admin
  • Go to Structure -> Blocks -> Add Block in admin menu or path "admin/structure/block/add"
  • Create a block with html content in Block Body, Click on "Switch to plain text editor" link below text area, paste the html, choose FULL HTML as format.
  • In region settings, choose the theme & region where you would like to enable the block.
  • In visibility settings, choose the pages where you would like to enable & roles it will be visible to.
  • Save Settings
  • Create a similar block with different html for different role & enable the block in same region with different role visibility.

Hope it helps.

View solution in original post

2 REPLIES 2

Hi Anton,

Out of the box, drupal supports 2 basic roles: registered users and anonymous (basically logged in and logged off).

You can find some more details on how to leverage them here:

http://docs.apigee.com/developer-services/content/add-and-manage-user-accounts#controllingwhocanregi...

Another option would be to use drupal modules to expand on the portal capabilities and configure full blown RBAC access into the portal. More details on this options is available here: http://docs.apigee.com/developer-services/content/managing-role-based-access-content-your-developer-...

I hope this helps,

Ricardo

@Anton+Bar , I believe your content is a HTML code.

Take a look at this article here which explains how to create custom blocks using module & enable them using context. If you have used custom_home blocks module attached in above article, It's taken care in the template. See custom_home_block2.tpl.php file that renders block 2 based on logged in user or not inside module template folder. See code below of same file.

<div>
    <div>
        <h1>APIs. APPs. Innovation</h1>
        <div>
            We are committed to work together to build <strong>Innovation</strong>, <strong>Apps</strong> and Developer communities. Driven by passion to innovate, We bring our services to you using <strong>APIs</strong>.
        </div>
        <?php
            global $user;
            if ($user->uid== 0) {
                ?>
                <div>
            <span>
                <span>
                    <a href="https://community.apigee.com/user/register">Join Now</a>
                </span>
            </span>
                    <span>
                <span>
                    <a href="https://community.apigee.com/user/login">Sign In</a>
                </span>
            </span>
                </div>
                <?php
            } else {
                ?>
                <div>
            <span>
                <span>
                    <a href="https://community.apigee.com/user/me/apps">My Apps</a>
                </span>
            </span>
                    <span>
                <span>
                    <a href="https://community.apigee.com/user">Profile</a>
                </span>
            </span>
                </div>
        <?php
            }
        ?>
    </div>
</div>

Also, If you don't want to put the code in a custom module & worry about drupal modules stuff. Easier way is to leverage the add block capability in out of the box CMS. See how to do same quickly below.

  • Login as Admin
  • Go to Structure -> Blocks -> Add Block in admin menu or path "admin/structure/block/add"
  • Create a block with html content in Block Body, Click on "Switch to plain text editor" link below text area, paste the html, choose FULL HTML as format.
  • In region settings, choose the theme & region where you would like to enable the block.
  • In visibility settings, choose the pages where you would like to enable & roles it will be visible to.
  • Save Settings
  • Create a similar block with different html for different role & enable the block in same region with different role visibility.

Hope it helps.