Solved

Coldfusion (Coldbox) - Side Navigation how to hide?

Posted on 2014-04-16
17
633 Views
Last Modified: 2014-04-23
Hi,

can you please help me to find out the solution for my navigation issue. some templates i don't want to show side navigation.
So i need to hide side navigation menu in some templates,by default it should be (true-display).
how can in do in coldbox environment ? my navigation menu is defined in layout template.
how can i tell template where to show menu where not ?

Regards,
0
Comment
Question by:xeondxb
17 Comments
 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 200 total points
Comment Utility
In your layout file, wrap the side navigation in a CFIF statement, something like:

 <cfif  NOT  (isDefined("request.hideSideNav") and request.hideSideNav is true)>
    ... .display side nav here...
</cfif>


Then in the templates where you want the side nav to be hidden, just set the variable..

 <cfset request.hideSideNav = true>

...as I side note, I feel compelled to give my 2 cents whenever someone is using one of these coding methodologies.   DON'T DO IT !!!
Over the years, many different coding methodologies come and go and get replaced by new ones, one thing is consistent, they don't do anything for you and then they because impossible to remember or find people to work on them.   They are all fads.   Your best bet is to keep your code really simple so you can easily work with it and ANYONE can take over for you if needed without needing training on an out-dated methodology.
0
 
LVL 4

Assisted Solution

by:Rodrigo Munera
Rodrigo Munera earned 100 total points
Comment Utility
I'm not a ColdBox user myself, but I just want to respectfully disagree on gdemaria's opinion that Frameworks are fads. Some may be better implemented than others, but in my opinion the worst case scenario (a framework that is no longer supported) is still usually better documented than most non-framework systems.

As to the OP's question, you can use gdemaria's approach to show/hide elements in the template, I would approach the issue from the navigation's point of view, if your navigation is database driven, why not just add a "sideNav" bit field in your navigation database table, and when you display the page, you can decide from the database if you're showing/hiding the page.

Not sure how ColdBox's approach to this is, but since ColdBox implements a form of MVC architecture, you'll likely have objects for your data access, business rules and views where your data object will get the navigation, and there's probably a property you can set up in your business model's object (something like "sideNavigation"), to either true or false, and then you can get the property value in your view object when you're rendering the page from the template to decide if it's being shown or not.
0
 

Author Comment

by:xeondxb
Comment Utility
hi Guys,
first of all sorry for late reply, i'll say thank  to @@gdemaria and @@Rodrigo Munera for comments.

@@gdemaria, i tried this, it is not working in my layout file(Layout/Main.cfm). I put my side navigation in IF block. and manually, im allowing where i need to show navigation in my View files.

@@Rodrigo Munera, i really love this idea next project i'll try this approach.
0
 
LVL 39

Expert Comment

by:gdemaria
Comment Utility
i tried this, it is not working in my layout file(Layout/Main.cfm). I put my side navigation in IF block. and manually, im allowing where i need to show navigation in my View files.

Well, there must be a simple issue somewhere.    Setting a variable and testing that variable in a CFIF statement is pretty straightforward.   Are you using the request scope in both locations?   Is the variable spelled the same in both spots?    Trying putting <cfabort> right after the location where you set the variable to make sure the code is reaching that spot.    If you have trouble, show some code so we can help find the problem...
0
 

Author Comment

by:xeondxb
Comment Utility
yes my variables are same both the side ... it seems like layout template is compiling before template called. Im learning coldbox .... that's why not a good idea about it. how compiling works with coldbox.
0
 

Author Comment

by:xeondxb
Comment Utility
...
0
 
LVL 4

Accepted Solution

by:
onlyamir007 earned 200 total points
Comment Utility
Your condition seems all wrong.

Try

<cfparam name="showSideNav" default="true"> <!---this sets the var to true if not declared in your template.. so showing sidenav by default--->

<cfif isdefined("request.showSideNav") and request.showSideNav is true>  <!---this is now your condition to wrap around the sidenav



Then in the template where you want to hide the sidenav put

<cfset request.showSideNav = false>


Also, this isn't really a coldbox question.,, more of a CF, or even general programming logic question, but hope it helps.
0
 

Author Closing Comment

by:xeondxb
Comment Utility
Thanks....
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 39

Expert Comment

by:gdemaria
Comment Utility
yes my variables are same both the side ... it seems like layout template is compiling before template called. Im learning coldbox .... that's why not a good idea about it. how compiling works with coldbox.

This is why you should not use Coldbox.  If it's your own website, that's fine, but you are doing an injustice to a client.  When you move on, the client will have a nightmare trying to get someone to come in and learn it just to support it.  Then they will want to rewrite the whole thing.    Alternatively, you will go back to it in a few years and curse yourself, because you've moved on to better methods.    Just do a simple page-to-self page and setup your files in the MCV format and everyone will be able to use it.
0
 

Author Comment

by:xeondxb
Comment Utility
@@gdemaria

you are absolutely right i agree 100% but problem in market clients asking these things. i Love to work without coldbox or anything it is easy for me. im learning coldbox because client want :( .... it is giving me also hard time ... straight things take time.

thanks your advice i'll keep it my mind.
You guys are gurus and i always keep gurus advice in my mind, it helps always...
0
 
LVL 39

Expert Comment

by:gdemaria
Comment Utility
Ha, see, that's exactly what I mean.   The client started with ColdBox and is now stuck with it.   Now he has to torture each of his new developers to work on the outdated methodologies or go through a full re-write.   Sorry you're stuck with it, good luck!
0
 

Author Comment

by:xeondxb
Comment Utility
:) thanks ....
0
 

Author Comment

by:xeondxb
Comment Utility
Hi

I have small query if u can answer here or if u want I can open new  question.

<cfoutput>
<form name="loginform" action="#cgi.SCRIPT_NAME#" method="post">
<!---
IN order for the controller to know where form is submitting,
place your event hidden element, to point to your handler's method.
Also, note that the form, submits to the cgi.SCRIPT_NAME

Example: General.doLogin.

The controller will instantiate the General handler and run the
doLogin method.  All the form variables and url variables are gathered
by the controller into the request collection.
--->

<input type="hidden" name="event" value="#Event.getValue("xehLogin")#">

<!--- Login Form --->
<br />
<br />
<table width="400" align="center" cellpadding="10" cellspacing="0"
style="border-bottom:2px solid ##ddd;border-right:2px solid ##ddd; border-left:1px solid ##eaeaea; border-top: 1px solid ##eaeaea;background: ##f5f5f5">
  <tr>
    <td style="font-family:Georgia, 'Times New Roman', Times, serif; font-size:25px"><strong>Login Form </strong></td>
  </tr>
  <!--- ColdBox messages box if errors --->
  <cfif not getPlugin("MessageBox").isEmptyMessage()>
  <tr>
    <td>#getPlugin("MessageBox").renderit()#</td>
  </tr>
  </cfif>
  <tr>
    <td>
      <p>Please use the form below to log in to the sample app. Use (admin/admin or lmajano/coldbox)    </p>
      <p>&nbsp;  </p>
      <table width="80%" align="center" cellpadding="5" cellspacing="0">
        <tr>
          <td><strong>Username:</strong></td>
        </tr>
        <tr>
          <td height="32"><input name="username" type="text" id="username" value="#Event.getValue("username","")#"></td>
        </tr>
      <tr>
          <td><strong>Password:</strong></td>
        </tr>
        <tr>
          <td><input name="password" type="password" id="password" /></td>
        </tr>
    </table></td></tr>

      <tr>
        <td align="right"><input type="submit" name="Submit" value="Login" /></td>
      </tr>
</table>
</form>
</cfoutput>

Open in new window



this is coldbox loginapp example
https://github.com/ColdBox/coldbox-samples/tree/master/applications/sampleloginapp

im not able to understand where is that piece of code
how login.cfm calling dologin method
0
 
LVL 39

Expert Comment

by:gdemaria
Comment Utility
Hmmm... the form posts to itself, that is, the same page is called on form post, so there must be something in either the application.cfc/.cfm file or the "controller" file that is triggering the doLogin function.

It could be triggered by either this event ..
<input type="hidden" name="event" value="#Event.getValue("xehLogin")#">

(because I don't know what that is, and it seems it could be the trigger for a login)

Or it could be simply testing for form variables username and password and figuring that if those two form variables exist, you may be trying to login.

So, I would search the controller file and the application file ... at least to start

... ah, the mysteries of coding methodologies.. so organized you don't know where anything is!
0
 

Author Comment

by:xeondxb
Comment Utility
:) when I was looking this code your words was in my mind .... why u don't like these kind of frameworks...


that mystery im trying to find that's way I was stuck... ...

Controller
<!-----------------------------------------------------------------------
Author 	 :	Your Name
Date     :	September 25, 2005
Description :

	coldboxSamples.system.eventhandler

----------------------------------------------------------------------->
<cfcomponent name="General" extends="coldbox.system.EventHandler">

	<!--- ************************************************************* --->
	<cffunction name="onRequestStart" access="public" returntype="void" output="false">
		<cfargument name="Event" type="any">
		<!---
		Security Check
		You need to check for the doLogin method, beacuse, if not, the doLogin method
		will never get a chance to be called.
		So check if the session.loggedin flag exists or not true, and if we
		are not logging in.
		--->
        
       
		<cfscript>
			var rc = Event.getCollection();

			//Set xeh's
			rc.xehLogout = "General.doLogout";
			rc.xehHome = "General.Home";
		</cfscript>
	</cffunction>
	<!--- ************************************************************* --->

	<!--- ************************************************************* --->
	<cffunction name="Login" access="public" returntype="void" output="false">
		<cfargument name="Event" type="any">
		<cfscript>
			var rc = Event.getCollection();
			//Set xeh's
			rc.xehLogin = "General.doLogin";
			//Set the page's title
			Event.setValue("title", "ColdBox - Sample Login App: Login page");
			/*
				The view "general/login" will be used by convention for this ebecause of the handler name "general" and the event name "login".
				Alternatly, you can manually set the view using
				Event.setView("general/login");
			*/
		</cfscript>
	</cffunction>
	<!--- ************************************************************* --->

	<!--- ************************************************************* --->
	<cffunction name="doLogin" access="public" returntype="void" output="false">
		<cfargument name="Event" type="any">
     
		<cfscript>
			//Do Login Procedure.
			var objDataStore = "";
			var rc = Event.getCollection();
			var ValidationStruct = "";
			//Error checks, does the form variables username & password exist
			//in the request collection? if they do, are they blank?
			if( not Event.valueExists("username") or not Event.valueExists("password") ){
				//Set a message to display
				getPlugin("MessageBox").setMessage("error","No username or password defined.");
				getPlugin("Logger").logEntry("error","Login without variables set detected.");
				//Redirect to next event, you can also add extra parameters to the URL
				setNextEvent("General.Login","username=#Event.getValue("username","")#");
			}
			else{
				//Init DataStorage
				objDataStore = CreateObject("component","#getSetting("AppMapping")#.model.datastore").init();
				ValidationStruct = objDataStore.validateUser(rc.username, rc.password);
				if ( ValidationStruct.validated ){
					//Login Correct.
					//set my session vars
					getPlugin("SessionStorage").setVar("loggedin",true);
					getPlugin("SessionStorage").setVar("name",ValidationStruct.qUser.name);
					//Log the entry
					getPlugin("Logger").logEntry("information","The user #validationStruct.qUser.name# has now logged in.");
					//relocate to home page.
					setNextEvent("General.Home");
				}
				else{
					//Set a message to display
					getPlugin("MessageBox").setMessage("error","Invalid Logon Information. Please try again");
					getPlugin("Logger").logEntry("warning","Invalid logon information detected. IP used: #cgi.remote_addr#");
					//Redirect to next event, you can also add extra parameters to the URL
					setNextEvent("General.Login","username=#Event.getValue("username")#");
				}
			}
		</cfscript>
	</cffunction>
	<!--- ************************************************************* --->

	<!--- ************************************************************* --->
	<cffunction name="Home" access="public" returntype="void" output="false">
		<cfargument name="Event" type="any">
		<cfscript>
			//Set the page's title
			Event.setValue("title", "Sample Login App: Welcome Back");
			/*
				The view "general/home" will be used by convention for this event
				because of the handler name "general" and the event name "home".
				Alternatly, you can manually set the view using
				Event.setView("general/home");
			*/
		</cfscript>
	</cffunction>
	<!--- ************************************************************* --->

	<!--- ************************************************************* --->
	<cffunction name="doLogout" access="public" returntype="void" output="false">
		<cfargument name="Event" type="any">
		<cfscript>

			//Delete login Information
			getPlugin("SessionStorage").clearAll();

			//Set the next event to display
			setNextEvent("General.Login");
		</cfscript>
	</cffunction>
	<!--- ************************************************************* --->
</cfcomponent>

Open in new window



application.cfc

<!-----------------------------------------------------------------------
********************************************************************************
Copyright 2005-2007 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
www.coldboxframework.com | www.luismajano.com | www.ortussolutions.com
********************************************************************************

Author     :	Luis Majano
Date        :	10/16/2007
Description :
	This is the Application.cfc for usage withing the ColdBox Framework.
	Make sure that it extends the coldbox object:
	coldbox.system.Coldbox
	
	So if you have refactored your framework, make sure it extends coldbox.
----------------------------------------------------------------------->
<cfcomponent extends="coldbox.system.Coldbox" output="false">

	<!--- APPLICATION CFC PROPERTIES --->
	<cfset this.name = hash(getCurrentTemplatePath())> 
	<cfset this.sessionManagement = true>
	<cfset this.sessionTimeout = createTimeSpan(0,0,30,0)>
	<cfset this.setClientCookies = true>
	
	<!--- COLDBOX STATIC PROPERTY, DO NOT CHANGE UNLESS THIS IS NOT THE ROOT OF YOUR COLDBOX APP --->
	<cfset COLDBOX_APP_ROOT_PATH = getDirectoryFromPath(getCurrentTemplatePath())>

	<!--- COLDBOX PROPERTIES --->
	<cfset COLDBOX_CONFIG_FILE = "">
	
	<!--- on Application Start --->
	<cffunction name="onApplicationStart" returnType="boolean" output="false">
		<cfscript>
			//Load ColdBox
			loadColdBox();
			return true;
		</cfscript>
	</cffunction>
	
	<!--- on Request Start --->
	<cffunction name="onRequestStart" returnType="boolean" output="true">
		<!--- ************************************************************* --->
		<cfargument name="targetPage" type="string" required="true" />
		<!--- ************************************************************* --->
		<cfsetting enablecfoutputonly="yes">

		<!--- Reload Checks --->
		<cfset reloadChecks()>
		
		<!--- Process A ColdBox Request Only --->
		<cfif findNoCase('index.cfm', listLast(arguments.targetPage, '/'))>
			<cfset processColdBoxRequest()>
		</cfif>
			
		<!--- WHATEVER YOU WANT BELOW --->
		<cfsetting enablecfoutputonly="no">
		<cfreturn true>
	</cffunction>
	
	<!--- on Application End --->
	<cffunction name="onApplicationEnd" returnType="void"  output="false">
		<!--- ************************************************************* --->
		<cfargument name="applicationScope" type="struct" required="true">
		<!--- ************************************************************* --->
		<!--- WHATEVER YOU WANT BELOW --->
	</cffunction>
	
	<!--- on Session Start --->
	<cffunction name="onSessionStart" returnType="void" output="false">			
		<cfset super.onSessionStart()>
		<!--- WHATEVER YOU WANT BELOW --->
	</cffunction>
	
	<!--- on Session End --->
	<cffunction name="onSessionEnd" returnType="void" output="false">
		<!--- ************************************************************* --->
		<cfargument name="sessionScope" type="struct" required="true">
		<cfargument name="appScope" 	type="struct" required="false">
		<!--- ************************************************************* --->
		<cfset super.onSessionEnd(argumentCollection=arguments)>
		<!--- WHATEVER YOU WANT BELOW --->
	</cffunction>
	
</cfcomponent>

Open in new window

0
 
LVL 39

Expert Comment

by:gdemaria
Comment Utility
Yah, it seems like the answer lies in these odd variables and event methods..

                  rc.xehLogout = "General.doLogout";
                  rc.xehHome = "General.Home";

But unfortunately, I lost my secret decoder ring.   Maybe you can convince the client to rebuild from scratch because he chose a coding methodology that is over a year old?

Sorry man... :)
0
 

Author Comment

by:xeondxb
Comment Utility
:) thanks man ...
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now