Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NESTING - Are there rules?

Status
Not open for further replies.

josel

Programmer
Joined
Oct 16, 2001
Messages
716
Location
US
Hello friends!

I am totally new to both HTML and CFML but not to programming. In the pass, I learned that you MUST close all functions or routines as you make your way out thus keeping your nested routines properly paired.

example:

if [ -s /tmp/filename ];
then
if [ -d /tmp/directory ];
then
for X in `cat /tmp/filename`
do
echo $X
done
fi
fi

Above you can notice a simple shell script with two if statements, one for/next loop and a do/while loop. Notice that they are all paired and closed in the way out of the nexted statemets.

I am playing around with some CFML/HTML and came across a sample where this rule does not seem to apply, which quite frankly, it throws me out of balance.

Sample (questionable) code:

<cfoutput ....>
<table .... >
<tr>
<td> .... </td>
</tr>
</cfoutput>
<tr>
<td> .... </td>
</tr>
</table>

How is it that <cfoutput> block can be closed before the <table> block? Is it a miracle that it worked? What are the chances that code like this will work a few year from now?

thank you all in advance;

josel





If you have the knowledge, consult and educate those who need it! - Jose Lerebours
 
if you use:

<cfoutput>
<table .... >
<tr>
<td> .... </td>
</tr>
</cfoutput>
<tr>
<td> .... </td>
</tr>
</table>

cf will make one pass over the code and it will generate this peace of html:


<table .... >
<tr>
<td> .... </td>
</tr>
<tr>
<td> .... </td>
</tr>
</table>


however, if you use <cfoutput query=&quot;somequery&quot;... that will require looping, if you look at the html source you will see that cf has generated something like this:


<table .... >
<tr>
<td> .... </td>
</tr>
<table .... >
<tr>
<td> .... </td>
</tr>
<table .... >
<tr>
<td> .... </td>
</tr>
<tr>
<td> .... </td>
</tr>
</table>

notice that the part that was enclosed within cfoutput has repeated itself and basically, you ended up with wrong html;

the secret is that if cfoutput is not used for looping, you can put those tags almost wherever you want, but if used to output queries where looping will be present, the code inside the cfoutput tags should only the code that you can and want to repeat

Sylvano
dsylvano@hotmail.com
 
I will take a shot at this. please correct if I am wrong.

It works because CFML is rendered independently of HTML. CFML is interperted on the Server and HTML is interperted at the client. As long as all the ColdFusion tags are opened and closed in the correct order. The CFML will produce the proper HTML. Then as long as the existing HTML intermixed with the new HTML are opened and closed properly the HTML should work fine.

As to whether or not this will hold true, a few year from now, who knows. The web world changes so rapidly that most of what you learn today is obsolete tomorrow.

hope i got it right, and hope it helps Randall2nd
 
Thank you guys your prompt and clear explanations. It looks like the miracle here is &quot;ColdFusion&quot;! :)

I guess that it will take a little getting used to it but then again, I am learning a new scripting/programming language(s) and there is always some degree of getting used to ...

I understand and appreciate the heads-up with <cfoutput> by itself instead of one which is within a loop, good advise and worth mentioning since this practice, if neglected, can cause problem.

Sylvano is right as far as any code been functional a few years from now - *ware evolution is taking us to un-imaginable horizons and anything we write or design today, will very likely be obsolete some time down the road! Talk about job security :)

Regards;

josel
If you have the knowledge, consult and educate those who need it! - Jose Lerebours
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top