Basically I need a way to inherit one HTML template(file) from another. The way I see it: parent.html:
<h1><!-- header --></h1>
<div class="container">
<!-- container -->
</div>
child.html:
<!-- extends: ./parent.html -->
<!-- <header> -->
Child Page
<!-- </header> -->
<!-- <content> -->
<span>Content</span>
<!-- </content> -->
Total duplicate of master page feature available in ASP .NET MVC or layouts of RoR.
Can anyone point me to a library that does something similar? (I going to use it as a loader for webpack, so if there is already a loader for this it would be perfect).
I recommend Nunjucks from Mozilla. You can use it via NPM or browser, also it is compiled.
https://mozilla.github.io/nunjucks/templating.html#template-inheritance
Related
I am developing using jQuery mobile and it has a multipage template as below.
I feel that writing html content inside the same html is bloated.
As such, i would like to separate the content in different html and include standalone html page. It should be mobile browser proven. What is the best practice on this and how it could be done?
Note: I do not expect server side scripting (eg: PHP) to solve this problem. It should be done solely on client side without any templating engine. Something like angularJS ng-include.
Sample of what i expect
<div data-role="page" id="foo1">
<html-include src="foo1.html"></html-include>
</div>
Mobile html multipage
<div data-role="page" id="foo1">
<!-- Content 1 here -->
</div>
<div data-role="page" id="foo2">
<!-- Content 2 here -->
</div>
<div data-role="page" id="foo3">
<!-- Content 3 here -->
</div>
<div data-role="page" id="foo1" data-url="foo1.html">
</div>
And use javascript like so:
$('[data-url]').each(function (k,elem){
$(elem).load(elem.data('url'));
});
This will find all elements that have data-url as attribute, and load that page in AJAX, takes the html received and put in it the corresponding html element.
I have been working on large angularJs application which have multiple modules. Problem is that now I have to include static website in that application and that website have whole different layout than my application.
I did some R&D and found some answers which were mostly dependent on angular.bootstrap
https://docs.angularjs.org/api/ng/function/angular.bootstrap
but my application's ng-view is declared in html tag not in body and further my layout is like mentioned below.
<div ui-view="header">
</div>
<div class="clearfix">
</div>
<!-- BEGIN CONTAINER -->
<div class="page-container">
<!-- BEGIN SIDEBAR -->
<div class="page-sidebar-wrapper" ui-view="sidebar">
</div>
<!-- END SIDEBAR -->
<!-- BEGIN CONTENT -->
<div class="page-content-wrapper">
<div class="page-content" ui-view="content">
</div>
</div>
<!-- END CONTENT -->
</div>
but website structure is totally different from this structure so can anyone please suggest how tackle this situation
should I use two ng-views in my index.html if yes than how can I use two ng-views while declare in html tag.
Thanks
What you're describing is like nested views? which the default router does not support so if you want to use of nested views for that you have to use third-party module.
I am looking at using Angular JS to mamange my HTML builds more effectively and am trying my hand at templating some of my HTML. However, it doesn't seem to work? I have;
<div class="container">
<div ng-include='"templates/menu.html"'></div>
<div class="row">
<div class="col-xs-12">
<h1>Hello, baby!</h1>
<p>This is the first ever Angular JS I have ever done.</p>
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="_includes/scripts/bootstrap.min.js"></script>
<script src="_includes/scripts/angular.js"></script>
Then I created a folder called, templates, where I have placed a HTML file, called menu, containing a navigation ul saving his obviously as menu.html. When I view index.html in my browser the menu is not rendered. Any help welcome. Thanks
Updated answer (summary of discussion below).
Working example in: http://jsfiddle.net/uo04c05h/
Angular should be started by ng-app directive
<div ng-app class="container">
Path to files is relative to the file where angular is initiated
Let's say I have a website, and on every page I import a header and footer that are constant.
<jsp:include page="header.jsp" />
<!-- Page contents go here. -->
<jsp:include page="footer.jsp" />
I tend to put my javascript code in the page header, but I don't want every page to have to load the java script for every other page. Equally, I don't really like my javascript being strewn throughout the content portion of all of my pages between the header/footer tags.
Is there a standard way of dealing with this? I'm fairly new to web development, so I'm sure there's a standard convention I just haven't run across yet.
Sure, I do the same thing with php.
I split my header into two, so I include three items:
<jsp:include page="headerTop.jsp" />
<!-- custom CSS links go here -->
<!-- javascript references go here -->
<!-- custom javascript goes here -->
<jsp:include page="headerBottom.jsp" />
<!-- Page contents go here. -->
<jsp:include page="footer.jsp" />
The headerTop.jsp file would contain the <head> tag, and the headerBottom.jsp file would contain the closing </head> tag.
combining with the first answer you could create a separate file webresources.jsp where you put in the css and javascript and then include the file to your pages:
<jsp:include page="headerTop.jsp" />
<jsp:include page="webresources.jsp" />
<jsp:include page="headerBottom.jsp" />
<!-- Page contents go here. -->
<jsp:include page="footer.jsp" />
I have a fixed navbar in the footer that looks like this (except I have a header aswell):
http://brooky.cc/wp-content/uploads/2011/04/nav_icon.png
When I change page from the homepage, users get the back button in the header. The problem is when the back button is tapped, the entire footer navbar disappears. I want the navbar there at all times. This problem occurs on the iPhone, but my desktop browsers work no problem.
My page setup is seperate files (one page per file) so I have index.php and products.php which are currently identical except for the header changed. The code is:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>
</head>
<body>
<div data-role="page" id="home">
<div data-role="header">
<h1>Home</h1>
</div><!-- /header -->
<div data-role="content">
<p>Home screen.</p>
</div><!-- /content -->
<div data-role="footer" data-position="fixed">
<div data-role="navbar">
<ul id="footernav">
<li>Home</li>
<li>Products</li>
</ul>
</div><!-- /navbar -->
</div>
</div><!-- /page -->
</body>
</html>
Chris, I fear that this is an unresolved issue, see
https://github.com/jquery/jquery-mobile/issues/1047
Some folks have recommended IScroll, which you might want to check out.
http://cubiq.org/iscroll
I've had the same problem, but was able to use another workaround for my case, which might be too much overhead for your case.
In our project, we decided to use jQuery templating, so all content of a page is created dynamically. See
http://api.jquery.com/category/plugins/templates/
I registered a callback with the pageshow event, and then filled a template. This is pretty straightforward as described in the jQuery template documentation. With this technique, I was able to avoid the bug, but I think checking IScroll might be worthwhile for you unless you already use jQuery templates.