printing large blocks of HTML in ASP

A

Andrew

I am making a web site and I am using ASP because of its templating
capabilities. My footer is an include file, for obvious reasons. I
can't use an include file for the header, because, while the top of
the page will be 90% similar, they will have different titles, page
titles, and left nav menus. I could write a function so that these
vars can be interpolated, except I don't want 70 lines of
Response.Write("foo") (there is a moderate amount of formatting on
each page). Does ASP have a "print HERE" function like Perl that
prints out large blocks of HTML and interpolates variables?

print <<<;
<html>
<head><title> strPageTitle </title>
<meta description="This site is an online for all those interested
in..">
</head>
<body bgcolor="wheat" leftmargin="0" link="blue" vlink="blue">
<center>
<table width="600" bgcolor="white">
<tr><td colspan="3" height="10">&nbsp;</td></tr>
<tr>
<td valign="top">
strMainLeftNav
</td>
<td width="10">&nbsp;</td>
<td><center> strPAgeTitle </center>
<p>
<table><tr><td>
<<<
 
D

David C. Holley

ASP can be used in this manner....

<% if a=1 then %>
Greetings World, we come in peace.
<% else %>
Greetings World, we come to conquer.
<% end if %>

Anything between the ASP blocks would be sent to the client as is. I
think that this is what you're looking for.

David H.
(Been thinking about "V" and "V-The Final Battle" recently)
 
A

Andrew

I just counted, and the top of my web page is 169 lines of HTML and
DHTML.

My question was really about printing out large blocks of HTML in ASP
clearly/efficiently (without using Response.Write("") 169 times), not
about printing different things depending on x or y.

-AK
 
D

Dave Anderson

Andrew said:
...Does ASP have a "print HERE" function like Perl
that prints out large blocks of HTML and interpolates
variables?

print <<<;
<html>
<head><title> strPageTitle </title> ...

You can certainly use the following in the same manner:

<html><head><title><%=strPageTitle%></title> ...

Since IIS 5+ defaults to buffering the response stream, there is little
penalty for this type of context switching.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
J

Jeff Cochran

I just counted, and the top of my web page is 169 lines of HTML and
DHTML.

Then use HTML/DHTML coding on the page for that section. Use
ASP/VBScript coding where appropriate.

Jeff
 
A

Andrew

I really appreciate everyone who is responding to my question. I have
an important point to clarify/reiterate. When I make web apps in PHP
or Perl, my pages look like this:

<?
include 'utils.inc';
$page = "Create Account";
printHeader($page);
?>

Enter your basic information here to create an account.<p>
Name: <input type="text" name="name" length="15"><p>
More content unique to that page.....

<?
printFooter();
?>

Isn't this brilliant?! Or is it crazy?
_I_create_functions_that_print_the_common_header_and_footer_sections_that_include_structural_HTML_
I don't just insert vars. This way, there isn't common HTML
duplicated across the 500 pages of the site I just inherited and am
upgrading. I am going by the programming paradigm of "if you use the
same thing over and over, just write it once and refer to it, don't
write it over and over." This way, if we decide to add another
hyperlink in the menu in the header, it is a 10 minute job, not a 15
hour job. The function printHeader is virtually all HTML, almost like
an include file. It ought to look virtually like an include file,
just all HTML like Perl's "print HERE" function. You ought to be able
to do this in ASP. How?

:)
-AK
 
M

Mark Schupp

<%@ LANGUAGE="VBSCRIPT"%>
<!--#include file="utils.inc"-->
<%printHeader "Create Account"%>

Enter your basic information here to create an account.<p>
Name: <input type="text" name="name" length="15"><p>
More content unique to that page.....

<%printFooter%>

You can use JScript if you prefer, but you'll have to get the correct syntax
from someone else.
 
D

David Holley

Are you familar with the server.execute method? It executes another HTML
page inline inserting any contained HTML or resultant HTML from ASP
code.

For Example....

<html>
<head>
</head>
<body>
Some sort of HTML code here
<% server.execute ("../content/getActiveReservations.asp") %>
Maybe some more HTML code here
<% server.execute ("../content/getCanceledReservations.asp") %>


</body>
</html>

Which might result in the following HTML...

<html>
<head>
</head>
<body>
Some sort of HTML code here
Active Reservations
1/1/2004 Smith, John
1/4/2004 Bush, George
Maybe some more HTML code here
Cancelled Reservations
1/3/2004 Johnson, Lyndon
1/3/2004 Nixon, Edward

</body>
</html>


Is this getting closer?

David H.
 
S

Stephen Willingham

Hello Andrew

Perhaps you are searching for something like this (although the solutions offered
above seem to be workable). I have an include file for each site called nav_inc.asp.
There are a couple of subs in there that look like this

--------------------------------------------
<%Sub WriteHeader()%>
<!--begin header-->

<h1>Some html for the header</h1>
...as much html as you care to include...

<!--end header-->
<%End Sub%>

<%Sub WriteFooter()%>
<!--begin footer-->
<h1>Some html for the footer</h1>
...etc
<!--end footer-->
<%End Sub%>
--------------------------------------------

Then in somepage.asp, I include nav_inc.asp at the top of the page and call functions
when I need them

-------------------------------------------
<%WriteHeader()%>

Enter your basic information here to create an account.<p>
Name: <input type="text" name="name" length="15"><p>
More content unique to that page.....

<%
'or if already within some scripting code, just call it without the asp delimiters

WriteFooter()

'some other server processing could be here...
%>
--------------------------------------------

If I understand your question, you just want to write *naked html* without wrapping
it
in 25 Response.Writes. This solution gets all of your common html blocks in one file.
I've also done it by putting the footer or header in it's own individual .asp file,
and then when you would like to write the footer or header, just include the file at
the desired spot in your code. You don't need to wrap the html in subroutine calls
and there does not have to be any asp delimiters in the include files, even though
they have .asp extensions.

--
HTH,
Stephen


Andrew said:
I really appreciate everyone who is responding to my question. I have
an important point to clarify/reiterate. When I make web apps in PHP> Enter your
 
S

Stephen Willingham

Sorry Andrew

I see the solution I just offered was already suggested out by Peter above. My
mistake.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top