How to reuse html code for multiple pages in jquery mobile.? - html

we are developing mobile app using jquery mobile & phonegap for various customers. Almost all the requirement completed but current requirement is each customer expecting different structure of html. how to make this possible satisfy the requirement?
i can duplicate of all pages and change the structure of html based on customers. But it difficult to maintain all these files i think so
in mvc we having partial view to achieve this, we expecting something same like partial view in html.
Thanks in Advance

Here are couple of approaches I have used in the past in different situations, in decreasing order of my personal preference:
1) Use JSP if your pages are going to live on the server and employ #includes to incorporate fragments of reusable JSP in a master page.
2) Use a template engine to place client-specific HTML fragments. You will be interleaving your business rules in the template's query language.
3) Use Jquery if your pages are packaged in a client app and use $.load() to load fragments of HTML. You will have to ensure that you do this before JQM begins its own life-cycle and fires its init events.
4) Use a Ant build script to do a client specific build using Ant's replace and token match tasks. YMMV with this approach based on the complexity of rules you need to check to create a page. Ant is just one option; any other build tool will provide similar function.
You will probably end up using multiple techniques from above for a complete solution.

Related

How to get data grid view using only jsp and my sql database

i want to take data from database as grid view.
i m using jsp and do not have knowledge about struts or any other higher feature than jsp.
Can any one give me the proper program with proper description/tutorial for why/how to use that program.
please provide the source code as soon as possible
You have many options -
front end - use a javascript library e.g. dojo
use backend to render
Personally I would go the dojo or similar route
http://dojotoolkit.org/documentation/tutorials/1.8/datagrid/
The grid rendered in javascript offers many options and keeps your display logic encapsulated.

Simple "server-side" HTML partials/templates/layouts?

I'm working with two students to produce a few HTML pages (a homepage and two secondary page layouts) that will later be implemented into a larger CMS.
I'd like to be able to abstract the shared HTML (head metadata, primary navigation, footer, etc.) into separate files so we only have to update them in a single place, execute a shell command to generate new, complete output. Since these pages are only ever going to become templates for another team, I don't even need to integrate any external data sources.
I know Jade would work for this but our partials/layouts/whatever need to look like HTML. I keep coming back to precompiling Handlebars templates but I'm not having much luck getting them to work.
Since we're using Foundation 5, Ruby and Node are already part of our toolchain. Suggestions?
I really like Middleman for this kind of thing. Layouts and partials and local data, etc. Wonderfully useful for doing front-end prototyping for what will eventually become a Rails application.

merging 2 html files into a single vm (velocity macro)

I have two html files, I used 2 different frameworks to create 2 different web application for smart phones and other devices such as tablets.
now I have to use Velocity Macro, and merge this two html files into a single vm, that generates 2 outputs depending on a configuration.
i have been searching for methods to do this and I found this: http://www.roseindia.net/apachevelocity/macro-wrap-html.shtml
My question is do I need to build a Java fie just like in the link and then make a vm file, or can I just make a single vm file without making any java files?
if my question in unclear let me know I try to explain more.
The Java class shown there is just to demonstrate the template, and all the template does is demonstrate how to use the Velocity #macro directive.
IMO putting both HTML files into a single VM template is a bad idea, because it will be large and difficult to understand, modify, and debug. Instead, consider using the #parse or #include directives.
Alternatively, consider a mechanism at a higher level to serve the appropriate pages directly instead of pushing the template decision-making process into the templates themselves--this is arguably the best solution.

Object-oriented HTML without server side code. Possible?

Is it possible to reuse HTML tags across multiple files, headers and footers for example? Placing them in separate files adds an extra HTTP request, that I'd like to avoid.
I don't want to replicate minor changes in headers and footers across every html file every time a change request comes along.
HTML is not a programming language - it's a markup language. You don't do object-oriented HTML because it isn't object based. This is the whole purpose of a server-side language, so you can make include files and use them in your server-side application.
If you have Apache however, you can use server-side includes which don't require a programming language such as PHP, but it's less flexible:
<!--#include virtual="/footer.html" -->
First, HTML isn't even a programming language, so it's impossible to have "Object-oriented" HTML.
Placing them in separate files adds an
extra HTTP request, that I'd like to
avoid.
If this is the reason for your "without server side code" requirement, then you are mistaken - the client does not fetch the templates that make up a page separately; the server side code will return a single HTML page to the client.
If, on the other hand, you don't have the option to run any server-side code at all and have to make do with static HTML pages, then there's only two options I can think of: iframes (which do result in separate HTTP requests, of course), or some sort of tool that basically runs the equivalent of server-side code to embed your reused templates everywhere and spits out the result to be uploaded to the server. You can have this effect by running a PHP/Apache-with-SSI/JSP/Whatever server on your development machine and using wget to make a static snapshot of the pages.
What I want to do is this. The files can be scattered during development. But I when I'm ready to release, a toolkit should compile the included files into a single html file.
You can use a template language/engine, such as jinja2.
You can layout files in a certain hierarchy, and have templates inherit from other templates, and include other templates, and define reusable macros (closest thing to what you referred to as "reusable tags").
What I want to do is this. The files can be scattered during development. But I when I'm ready to release, a toolkit should compile the included files into a single html file
I know this is late, but CodeKit's .kit language lets you do exactly what you were saying.
http://incident57.com/codekit/help.php
I think the language you've chosen in your question (object oriented HTML) is actually masking the real issue you have here...
What I want to do is this. The files can be scattered during development. But I when I'm ready to release, a toolkit should compile the included files into a single html file.
This sounds like a job for a preprocessor, I don't believe it has anything to do with your webserver or server side technology, as this is a step which would happen before deployment.
There's a number of text pre-processors available eg M4 - hell you could even use the C compiler pre-processor if you wanted. A quick google reveals that there are specialised pre-processors for HTML as well....
Automatic file inclusion, automatic escaping, and whatnot that can be done with automatically inserted headers and footers, chosen based on path patterns.
Seems to fit the bill?
Sure . But these would have to be separate ajax calls form the client . There are lot of javascript mvc frameworks like that do that .
If you want to have include files during development, then compile them into free-standing HTML files, you could do that by spidering your development server with wget: whatever server-side technology you use will combine the files and return the HTML, which wget will saves as one file.
As everithing is object over the technology but not directly, indirectly interacting with the object that are created at different level as per security implementation.
You can do this.
I just released a mature framework called Hypertag that is, in fact, Object Oriented HTML. It is entirely client-side, in continuous development, and allows for very interesting, yet HTML-compatible, advanced solutions for logic and layout.
See http://hypertag.io for more.

How do you organize views / controllers in a NON MVC web application?

looking for best practices in web development, when you are writing a web application in a traditional non-framework environment (core PHP or Perl / CGI), what is the cleanest way to organize or map calls from the client to server processes?
The answer is rather trivial when working in a single-scope page where, for example, you have a form to complete and a submit button. You could set the action of the form to "save.php" and have a one-to-one relation between the page and the function it is bound to. So save.php could execute the save action and write to the client the form.
Now, the only non out-of-the-box php enhancement i'm using is a template engine (tinybutstrong). Whenever i have a complex page with multiple forms (for example, for sorting a grid, saving something, requesting something else, an ajax component and a search box), what is your way to lay down the various functions (search, sort, insert, retrieve) to a single display page (index)?
Do you use something like index.php?action=search / index.php?action=insert or something like setting each action to a page that acts like a function (search.php, sort.php, insert.php) each delegating the presentational function to a single script (index.php)? What if the "search" function can be used by varius "views"?
I'm using general terms like search or insert as an example, and the referece to PHP is also only for example, as I think my question is rather general on best practices.
Thanks.
By creating something where there's an action which refers you to a view, you're essentially creating a controller for views, and you're two thirds of the way to MVC. (not that there's anything wrong with that, just that's where you're headed)
Q1. what is the cleanest way to organize or map calls from the client to server processes?
A1. Using the filesystem, but structured semantically based on the structure of your data (if possible) doing something like /search/mysearch is your semantically correct option. Requires a little Apache Mojo
Q1. Do you use something like index.php...
A1. Yes, I wouldn't shy away from this approach. It's ideal to use a little Apache rewrite magic to create nice paths, but aside from that, there isn't any other magic way to create an controller.