Skip to main content
Participant
Mar 23, 2023 7:13 PM UTC
Question

Display a navbar or hide it by page

 I have a website where the navigation bar appears on every page. This is so I can edit the navbar in one location and it will change in each subsequent page automatically. However  I want to have the option to display the navbar or not display it based on the type of page that it is.

 

I achieved the navbar being displayed on each page via my application.cfc under  the “request start“ tag. Is there a way that I can selectively omit my navigation bar depending on the page that I select?

 

Any suggestions on the direction? I should go with my coding

 

<cffunction name="onRequestStart" returnType="boolean" output="true"> <!--- Any variables set here can be used by all our pages --->

 

<!---02/20/2023--->

<cfinclude template="navbar_admin.cfm">

<cfset request.companyName = "BK_Club">

 

    This topic is closed to new replies. Start a new post to keep the conversation going.

    3 replies

    BKBK
    Community Expert
    Community Expert
    Apr 25, 2023 11:34 AM UTC

    I am assuming that the list of CFM pages you wish to omit is fixed throughout the duration of the application. Then I can think of an easy solution. In ColdFusion.

     

     

    <!--- In Application.cfc's onApplicationStart() --->
    
    <!--- Define array of CFM pages for which to omit the navbar --->
    <cfset application.arrayOfPagesToOmitNavbar=["page123.cfm","page987.cfm","page456.cfm"]>

     

     

    <!--- In onRequestStart() --->
    
    <!--- Check if current CFM page is in array of pages for which to omit the navbar --->
    <cfset var currentPage = listLast(arguments.targetPage, "/\")>
    <cfset var currentPageOmitsNavbar = application.arrayOfPagesToOmitNavbar.containsNoCase(currentPage)>
    
    <!--- Check if current page allows navbar --->
    <cfif not currentPageOmitsNavbar>
        <cfinclude template="navbar_admin.cfm">
    </cfif>

     

     

     

     

    Translate
    BKBK
    Community Expert
    Community Expert
    May 15, 2023 10:45 AM UTC

    Hi @HumbleCF ,

    Did our suggestions help?

    Translate
    Participating Frequently
    Mar 24, 2023 2:07 PM UTC

    Depending on the complexity of your nave bar, an option is to hide it via client side using JS/Jquery/css that is controled on the page. Our nav bar is really simple so hidding it is not that a big deal.

    Translate