VisualForce: Conditionally render HTML elements like
  • I have a Force.com site portal written completely with custom Visualforce, HTML and CSS.

    I have a component which is used to display the navigation links at the top of the page.
    This navigation is built using and

  • tags which is pretty common.

    <ul id="hdrnav">
                    <li><a href="/apex/billing" id="billnav">Billing</a></li>
                    <li><a href="/apex/deposits" id="depositsnav">Deposits</a></li>  
                    <li><a href="/apex/checks" id="checksnav">Checks</a></li>   
    
                </ul>
    

    Now I want to be able to render these

  • links based on the user’s security as each of these links display information from different custom objects.

    I know we can check a user’s access to a record using something like:

    {!$ObjectType.objectname.accessible}
    

    So how can I achieve something like not displaying the

  • link for deposits if the user has no access to the deposit custom object.

  • Answer

    Off the cuff, I believe you can overload the use of the <apex:variable> tag along with its rendered attribute to show/hide individual elements.

    <apex:variable var="foo" rendered="{!$ObjectType.objectname.accessible} >
        <li> bar ... </li>
    </apex:variable>
    

    Attribution
    Source : Link , Question Author : Richard N , Answer Author : isherwood

    Leave a Comment