can anyone see why using this code:
<% select case edit
case "specs" %>
<!-- #include file="edits/specs.asp" -->
<% case "desc" 'LINE 28 HERE %>
<!-- #include file="edits/desc.asp" -->
<% case "review" %>
<!-- #include file="edits/review.asp" -->
<% case "images" %>
<!-- #include file="edits/images.asp" -->
<% case "floor" %>
<!-- #include file="edits/floor.asp" -->
<% case else %>
<!-- #include file="edits/main.asp" -->
<% end select %>
is creating this error:
Microsoft VBScript compilation error '800a0400'
Expected statement
/*****.com/edit2.asp, line 28
case "desc"
^
Because it seems ok to me and the blogs I've found about it, (asp isn't exactly my best language though)
<%
select case edit
case "specs"
call server.execute("edits/specs.asp")
case "desc"
call server.execute("edits/desc.asp")
case "review"
call server.execute("edits/review.asp")
case "images"
call server.execute("edits/images.asp")
case "floor"
call server.execute("edits/floor.asp")
case else
call server.execute("edits/main.asp")
end select
%>
Related
In Silverstripe templating, the $Up tag temporarily breaks out of the current loop/with and gives access to the parent scope. While the following template code works, I don't understand why.
$Checked is a list with objects that I loop, in itself containing a list with $Items of which I need to show the first. The object also has an Owner, which I need to access while in the scope of the first item.
I've got the following silverstripe template code:
<% loop $Checked %>
<% with $Items.First %>
<article class="checked-statement">
<span class="statement-outcome h-bg-true-$Verdict.Value">$Verdict.Name</span>
<div class="checked-statement__statement">
<a href="xxx" class="checked-statement__picture"><img
src="$Up.Up.Owner.Photo.CroppedImage(160,160).Url" alt="$Up.Up.Owner.Name.XML" class="h-full-rounded"/></a>
$Up.Up.Owner.Name zei
<h3>
$Up.Up.Title
</h3>
</div>
<a href="yyy" class="checked-statement__argument">
$Up.Up.Statement…
$Top.Icon('chevron-right')
</a>
</article>
<% end_with %>
<% end_loop %>
I would think I would need only one "Up" to get to the scope of $Checked. But I need two, which is strange, as the first Up should break out of the "with", and the second one should break out of the loop, giving me the top level scope, in which the specific item is not available...
Can anyone point me at the fault in my reasoning, or code?
At some point, I believe it was with 3.0 or 3.1, the logic behind $Up changed.
Previously <% with $Items.First %> or back in 2.x <% control $Items.First %> was just one scope level that you could break out of with $Up.
These days, each object/method call/property gets it's own scope. This means:
<% with $Foo.Bar %>Foo's ID: $Up.ID<% end_with %>
<% with $Foo.Bar %>Outside of "with" ID: $Up.Up.ID (== $Top.ID in this case)<% end_with %>
And for deeper nesting you need even more ups:
<% with $Foo.Bar.X %><% loop $Y %>$Up.Up.Up.Up.ID == $Top.ID<% end_loop %><% end_with %>
What happens if I include 2 pages conditionally?
<% if(x==1) {%>
<!-- #Include virtual="/ws/inc/Master1.inc" -->
<% } else { %>
<!-- #Include virtual="/ws/inc/Master2.inc" -->
<% } %>
Which command runs first? Are both included at first, and then the if clause is evaluated, or will just one of them be included?
I want to be sure not to include the wrong page at all.
It depends on the condition. If you don't have the statement inside a loop where you iterate through x or something similar, I think only one page will be included depending on the value of x
How do I rewrite the following PHP code in Classic ASP?
<head></head>
<body>
<h1>Test</h1>
<section><?php echo include('content/'.$_GET['p'].'.php') ?></section></body>
If the url is http://foo.bar.com/admin.php?p=pages, then content/pages.php is shown.
You can't do this with INCLUDE but you could use Server.Transfer instead, eg.
Server.Transfer "content/" & Request.Form("p") & ".asp"
Never trust what comes from the clientside (browser) as they can try to hack you.
Since it is not likely that "shdyhio3hlkehio.asp" or similar is a proper file, you should limit the options to your actual selection and also have a default file which is a "catch all other requests".
Combine that with Server Side Includes and you have your setup ready.
You should also check if the user actually requested a page -- if "p" is empty then show a default message.
Note the use of LCase in the "Select Case"-line and lowercase values in the Case-lines.
This is due to the face that the string comparison is case-sensitive, meaning "about" (lowercase "a") and "About" (uppercase "A") is not the same.
Eksemple:
<% If Request.QueryString("p") = "" Then %>
no specific page was request, show a default message
<% Else %>
<% Select Case LCase(Request.QueryString("p")) %>
<% Case "content" %><!-- #include file="content.asp" -->
<% Case "about" %><!-- #include file="about.asp" -->
<% Case "contact" %><!-- #include file="contact.asp" -->
<% Case Else %><!-- #include file="404.asp" -->
<% End Select %>
<% End If %>
You can use something like this
<!--#include file="somefile.asp"-->
in your HTML file .
Ok, I'm new to the asp/vbscript world. I am working at a new company and am trying to reproduce a script I use on almost all projects when developing under php.I have two functions one called showHeader and one called showFooter. These functions both get arguments passed to them and those arguments need to be displayed in the included file. For example in php my showHeader function is like so
<?php
showHeader($page,$title,$passedCSS,$desc,$keywords) {
include("header.php");
}
?>
Now in the include file i can echo out the contents of any of those arguments simply by calling echo $var and i get the contents. Is this possible with vbscript. I'm having no luck what so ever.
#projectxmatt: You could do something like --
In header.asp:
<%
Sub showHeader(page, title, passedCSS, desc, keywords)
%>
<!-- some HTML code here -->
<title><%=page %></title>
<!-- more HTML code here -->
<%
End Sub
%>
In somefile.asp:
<!-- #include file="header.asp" -->
<% showHeader "value-for-page", "My Page Title", "", "", "" %>
With ASP you have to specify all the variables you have in your Sub or Function, they can't be left out or assigned with a default as in PHP if none was passed to the function (e.g. function showHeader(title = 'Default Value'))
Ok here is what i did
global.asp
<%#LANGUAGE="VBSCRIPT"%>
<%
Sub showHeader(page,title,passedCSS,desc,keywords)
%>
<!---#include file="header.asp"--->
<%
end Sub
Sub showFooter(passedJS)
%>
<!---#include file="footer.asp"--->
<%
end Sub
%>
Then in header.asp and footer.asp I passed in the vars just using <%=varname%>
Then in the main.asp my code was as follows.
<!---#include file="global.asp"--->
<% showHeader "Home","Test Page","test.css","Description","keywords" %>
<section>
</section>
<aside>
</aside>
<section>
<h2></h2>
<ul>
<li><article></article></li>
<li><article></article></li>
</ul>
</section>
<section>
<div></div>
<div></div>
<div></div>
</section>
<% showFooter "testjs.js" %>
And everything works great.
Response.Write would be another solution you could use to write output in classic ASP.
Is there a way to include a VBScript page into an ASP page written using Javascript?
There is an ASP page written in Javascript, but our sidebar menu is written in VBScript. When I include the sidebar asp file into the Javascript the server gives an error.
< %# LANGUAGE="JavaScript" %>
<%
...
< !--#include file="sidebar.asp"-->
...
where sidebar.asp is written using VBScript.
You can try this, but my guess is that the sidebar.asp will be executed before your Javascript code.
< %# LANGUAGE="JavaScript" %>
<%
...
<script language="VBscript" runat=server>
< !--#include file="sidebar.asp"-->
</script>
...
I do this all the time, but I write my ASP/JScript pages a bit differently. Instead of switching the page language to "JavaScript", I leave it at the default "VBScript" and then use a <SCRIPT LANGUAGE="JavaScript" RUNAT="Server"> block for my JScript code. The JavaScript SCRIPT blocks are executed before the normal <% %> tags, so I do all my page processing in the SCRIPT blocks and then simply plug the results into the page with <% %> tags. Here's an example:
mainpage.asp:
<SCRIPT LANGUAGE="JavaScript" RUNAT="Server">
var name;
var address;
var phone;
function main() {
var rec = go_to_database();
name = rec.first_name + " " + rec.last_name;
address = rec.address;
phone = rec.phone;
}
</SCRIPT><% main() %>
<html><head><title><%= name %></title></head><body>
<p>Name: <%= name %><br/>
Address: <%= address %><br/>
Phone Number: <%= phone %></p>
<!--#include file="subpage.asp"-->
</body></html>
subpage.asp:
<p>Blah blah blah, some random VBScript code: <%
Dim whatever
whatever = some_silly_thing()
Response.Write(whatever)
%>.</p>
So, first IIS processes the SSI and includes subpage.asp into mainpage.asp. Then, it evaluates the JScript SCRIPT block, declaring the variables name, address, and phone and defining the function main.
Then it evaluates each <% %> tag in order. <% main() %> call the main function and sets values for name, address, and phone. Then <%= name %>, <%= address %>, and <%= phone %> substitute those values into the page. Finally, the <% %> code from subpage.asp is evaluated and the Response.Write value ends up in the page output.
While the whole page is not written in JScript, the vast majority of the code can be, inside the SCRIPT block. Would that work for you?