VisualForce: Conditionally render HTML elements like
  • I have a 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>   

    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:


    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>

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

    Leave a Comment