I'am making a dynamic website in which the positioning and components of certain components like the fixed header, menubar, footer etc are common in almost all the pages. So how do I include this fixed components in my every webpage? I'am using JSP and javascript.
Thanks in advance.
If you are including static content then you can use
<%#include file="includes/header.html" %>
or for dynamic content
<jsp:include page="includes/header.jsp" />
From http://docs.oracle.com/cd/E19159-01/819-3669/bnajb/index.html:
Reusing Content in JSP Pages
There are many mechanisms for reusing JSP content in a JSP page. Three
mechanisms that can be categorized as direct reuse are discussed here:
The include directive
Preludes and codas
The jsp:include element
An indirect method of content reuse occurs when a tag file is used to
define a custom tag that is used by many web applications.
The include directive is processed when the JSP page is translated
into a servlet class. The effect of the directive is to insert the
text contained in another file (either static content or another JSP
page) into the including JSP page. You would probably use the include
directive to include banner content, copyright information, or any
chunk of content that you might want to reuse in another page. The
syntax for the include directive is as follows:
<%# include file="filename" %>
For example, all the Duke’s Bookstore application pages could include
the file banner.jspf, which contains the banner content, by using the
following directive:
<%# include file="banner.jspf" %>
Another way to do a static include is to use the prelude and coda
mechanisms described in Defining Implicit Includes. This is the
approach used by the Duke’s Bookstore application.
Because you must put an include directive in each file that reuses the
resource referenced by the directive, this approach has its
limitations. Preludes and codas can be applied only to the beginnings
and ends of pages. For a more flexible approach to building pages out
of content chunks, see A Template Tag Library.
The jsp:include element is processed when a JSP page is executed. The
include action allows you to include either a static or a dynamic
resource in a JSP file. The results of including static and dynamic
resources are quite different. If the resource is static, its content
is inserted into the calling JSP file. If the resource is dynamic, the
request is sent to the included resource, the included page is
executed, and then the result is included in the response from the
calling JSP page. The syntax for the jsp:include element is:
<jsp:include page="includedPage" />
The hello1 application discussed in Packaging Web Modules uses the
following statement to include the page that generates the response:
<jsp:include page="response.jsp"/>
So you may use
<jsp:include page="includepage.jsp" />
You can use
<head>
<?php include("path/webpage.html"); ?>
</head>
Related
I was wondering if there is a way to add JavaScript files to individual views if I am using a wrapper .cshtml file.
Basically I have a wrapper cshtml file called _Layout that I am using for all my front end views. It basically has the <header> section and the HTML for my header/navigation and the footer. It also contains references to all the JavaScript files I need on each page after the footer.
However, on my contact view I want to use another JavaScript file, but I don't want to add it to the wrapper as that will add it to every single view.
Is there anyway to get add the file to the wrapper using a conditional statement - i.e. if Contact view then reference the contact JS file?
You can use Razor's section. It allows you to create "sections" in your layout page, and then add to them from your view pages.
You might already have a section "Scripts" declared in your layout page. If not, all you need to do is add #RenderSection("Scripts", required: false) in your layout, immediately after your other script tags. This creates a section called "Scripts" which we will add to later.
Then, you can add to that section by adding the following to your individual views:
#section Scripts {
<script type="text/javascript" src="..."></script>
}
You can do this with other elements as well; you aren't limited only to scripts. You'll just have to add another #RenderSection("SectionName", required: false) to your layout page.
You might also be interested in reading Scott Gu's slightly dated (2010) blog post on Layouts and Sections with Razor.
I have a fully functional html page(js and css) working properly to my local browser. But I want to add this html file into wordpress page.
I tried to add the whole html code in wordpress page in text mode(not visual), but it not proper work. Js and css design not working.
So please guide me how to add this html page to work properly.
Thanks
Make a page template.
Use this:
https://developer.wordpress.org/themes/basics/page-templates/
Page Templates within the Template Hierarchy #
When a person browses to your website, WordPress selects which
template to use for rendering that page. As we learned earlier in the
Template Hierarchy, WordPress looks for template files in the
following order:
Page Template — If the page has a custom template assigned, WordPress
looks for that file and, if found, uses it.
page-{slug}.php — If no custom template has been assigned, WordPress
looks for and uses a specialized template that contains the page’s
slug.
page-{id}.php — If a specialized template that includes the page’s
slug is not found, WordPress looks for and uses a specialized template
named with the page’s ID.
page.php — If a specialized template that includes the page’s ID is
not found, WordPress looks for and uses the theme’s default page
template.
index.php — If no specific page templates are assigned or found,
WordPress defaults back to using the theme’s index file to render
pages.
To create a global template, write an opening PHP comment at the top of the file that states the template’s name.
<?php /* Template Name: Example Template */ ?>
I have pages set up with razor code to use a consistent layout on every page.
I don't want the pages url to display with the .cshtml tag
How can I do this. I use JQuery, JavaScript, HTML, CSS, ASP.net (web Pages Logic)
EX URL; http:// www.site.com/page.htm
I am new to ASP and server side stuff.
#{
Layout = "~/Shared/_Layout1.cshtml"; <!--i use a _PageStart.cshtml that contains this line for dry purpose-->
Page.title = ""; #*add pages title here*#
}
<!--If you want to add Page specific stylesheets Link them here with HTML tags-->
#section ExtraHeadContent {
}
#section NavBarLinks {
<!--Enter links here for the top navigation bar <a class="topnav-link" href="~/index.html">| Home</a> -->
}
<!--Enter the Pages HTML content here. This will be displayed in the white content div-->
If there are any relevant pages or discussions you've found in the past please share.
The built in routing system within the ASP.NET Web Pages framework allows you to omit the file extension altogether. If you request www.yourdomain.com/YourPage (where YourPage represents a file called YourPage.cshtml), it should work by default. You can read more about it here: http://www.mikesdotnetting.com/Article/165/WebMatrix-URLs-UrlData-and-Routing-for-SEO.
As for replacing the file extension with .htm, I'm not sure that you hope to achieve by doing that. It won't improve SEO. However, one option would be to use a Nuget package called WebPageRouteHandler. I've written about that too: http://www.mikesdotnetting.com/Article/187/More-Flexible-Routing-For-ASP.NET-Web-Pages. Mapping each file individually could be a pain, but you could generate the routes dynamically from a database or from looping through the physical files to reduce the code required.
It's a known fact that jQueryMobile loads pages with ajax and is not including in DOM the header content in every pages.
I need to load a custom js file in some pages, how can I achieve this? Until now I have placed the .js files in the body, but there are some problems with the code there too so it's not a good workaround. Until I can find a solution I will use the rel="external" workaround, but I really need to find an answer to my question.
You could try including the custom script within the data-role="page" div in pages where you want to use those javascript.
From JQM docs:
Another approach for page-specific scripting would be to include
scripts at the end of the body element. If you include your custom
scripting this way, be aware that these scripts will execute when that
page is loaded via Ajax or regular HTTP, so if these scripts are the
same on every page, you'll likely run into problems. If you're
including scripts this way, we'd recommend enclosing your page content
in a data-role="page" element, and placing scripts that are referenced
on every page outside of that element. Scripts that are unique to that
page can be placed in that element, to ensure that they execute when
the page is fetched via Ajax.
You could use some javascript to dynamically add the js file to the DOM.
This is demoed here: http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml
in view, i have at the bottom many javascript and jquery code, and i dont like it, so im placing all scripts into one ascx file, and make partial rendering like:
<!--<%Html.RenderPartial("~/Views/Home/StationLogics.ascx"); %>-->
of this ascx file with scripts. So, is there any better way?
cant place it to master page, cause not always i need this scripts, if user get some privilage, he can use some scripts, if not - others
it mat not be what u intended to know but i think that u can place all ur javascript and jquery code in a js file like in yourjavascript.js file and place a reference of js file in your view or the master page page file that the view is inheriting e.g.
<script src="<%=ResolveUrl("~/scripts/yourjavascript.js") %>" type="text/javascript"></script>
You could add your common JavaScript files in the head element of a Master page, and then let your pages reference that master page using the <%# Page %> directive, for example:
<%# Page MasterPageFile="/Views/Shared/Site.Master" %>
Now, all you have to do is update the scripts in your master page, and pages referencing that master page will have the scripts as well.
However, if your scripts are too specific to include in the master page, then your solution is probably fine.