how write text/template in a file and include it to project - javascript

I use script type="text/template" for my project and I use a lot of templates, I want write my template in foreign file and include it to my html
If its possible , what type of file must i use and how must write it ?

In a pure JavaScript/HTML environment, you can't easily.
Your choices are:
Use some kind of JavaScript template library
I'm only familiar with Durandal that uses the Knockout engine.
AngularJS seems to be another popular choice.
Most of these packages include far more than just templates and may be overkill.
Use a server-side template package
PHP is a popular server-side tool.
Some HTTP Servers support Server Side Includes, but these are so limited I couldn't actually recommend them.

Related

Creating Templates with HTML CSS and JS

I have to use static hosting to create a website, how can avoid duplicating code without processors like blade or php.
I'm trying to use Firebase but I can't think of anyway to do this, I would normally use blade.
The only way I can thing of is using Dreamweaver templates but I really don't want to regress to that.
The way to go on this is to use a STATIC SITE GENERATOR, that will allow you to use partials(includes in PHP) there are a lot to choose from but a good recommendation is to use middleman here is the link to MiddleMan partials docs. good luck.
I use Yeoman with Yeogurt which uses Jade by default for templating but can use Nunchucks. You can use LESS or SASS/SCSS. Really good if you want to create a nice tidy static site. It takes JSON fixtures too so you can even create data for the site and compile it all down into static html, minified css and js, and compressed images.

Which editor to use for coding dynamic web pages

I am new to web development and I see it is very common to print HTML syntax from some server side script which is typically written in python, php, perl etc.
Now, normally all editors have some features which can help with syntax checking of the HTML as the programmer is writing them.
However, if the HTML code is emitted from a print statement, how can HTML syntax checking be done.
For example
the server side python script generating an HTML form can be like
print("<td><input type="file" name="upload_file" />")
Here the ending tag
</td> is missing. Is there an editor which can warn about this. Otherwise, how do the programmers deal with it.
You can't display this code using python. If you want to create a server, you will need to look for the development of the server side (these are the three most used):
Flask
Django
Tornado
Also, you can check more web frameworks here: https://wiki.python.org/moin/WebFrameworks
use sublime, its light weight and have lots of features.
For any non-trivial work it's best not to embed HTML (or any other language) in your Python code. Use a templating engine such as jinja2 or one of the others available. Most Python web frameworks support integration with at least one templating engine.
Separating your code and markup by using a templating engine makes your code easier to maintain. In particular, files for templating engine code are essentially HTML with some additional markup to allow for variable substitution, looping etc and so your editor's HTML syntax highlighting will work on them.

Webpage-text translation on client-side (without internet connectivity)

I need a web-application to be translated from English to Portuguese.
Since the servers on which this application runs have no internet access, is there a way to achieve this without using a 3rd Party API. Is there a JS Library that can translate from say Language A to Language B on the client side ?
You can definitely use Java Script for that.
The library well known for translations is the i18next
You can integrate with jQuery, but I strongly recommend you using something like AngularJS or Mustache for customise your template.
If you choose use AngularJS you can have a different JSON file with your expressions, and depending on the language you are navigating, loads a different JSON file, like:
en.json, es.json, pt.json
You can use JS Cookies for saving the language as same you would do with any backend language.
Mustache is used to create templates front-side with double brackets {{custom_text}}. AngularJS uses the same idea.
The only issue if you want to use AJAX. Read more about Google Chrome --allow-file-access-from-files disabled for Chrome Beta 8

Include html files in an html file on a local file system?

I have a help system that is completely offline, no server, using file://.
I have one main page, with hundreds of line of html that represent many sections of the help system. I would like to stick each section in a html file and just include it. Unfortunately it seems like this is only possible with some nifty server side include techniques, with HTML5 (which I do not want to assume my users have), or with a nasty javascript hack where you copy your html file into js files with document.write calls for every line as written about here: Ways to include html in html.
What about something like handlebars.js or mustache.js? Can I use templating?
Since you don't want to use server-side includes, I would suggest using a static site generator (SSG).
If you are not familiar with SSG's, they allow you generate HTML pages from templates & includes (often Handlebars templates) and HTML, Markdown, JSON, or YAML, content using a CLI.
If you want to get started with an SSG, there are plenty of options, from Ruby based Jekyll, or Node.js based Assemble. In my opinion, Assemble is the best option and I would highly recommend it.

MVC Bundles vs Javascript modules

As a ASP.NET MVC developer, I am trying to wrap my head around JavaScript AMD modules and libraries like RequireJS.
What is the relationship between ASP.NET MVC ScriptBundles and RequireJS?
In a large site with lots of JavaScript, should I be using both? Or one of them?
Should I integrate RequireJS with Bundles using IBundleTransform?
I wouldn't see using the two of these together. With Bundles you would have all your JavaScript loaded, ideally into just one or two bundles, on your layout controller. In production it would be optimized (combining into one file, minimised, cached and compressed etc).
RequireJS the way I see some of it is if you are being more granular about what JS is loaded and then you can use it's terse syntax to ensure a certain file is loaded before invoking some of that file's JavaScript.
I would recommend using Bundles since you are working with asp.net-mvc. They are pretty to use and work very well. I had used a similar pre mvc4 framework called Combres which was similar and this approach works very well for apps I think. It may be different for read only web sites.

Categories