I've been struggling to understand Handlebars ever since I was introduced to it in class. I've researched different resources and videos (e.g., YouTube, StackOverflow, etc.) to try and learn more about it, but I still feel like I'm not getting it.
Could somebody please either explain to me what Handlebars is in their own terms or send me resources they found helpful when learning it?
Thanks!
handlebars.js is a templating engine which allows dynamic data to be mixed in with your HTML code. Templating engines were created due to complex projects requiring a lot of dynamic HTML manipulation. Previously, software developers created new chunks of HTML code and dynamically inserted them into the DOM using Javascript. This eventually became unwieldy and difficult to maintain. Also, it lead to repetition of code. To solve this issue, templating engines allowed one to create predefined templates to be used in multiple locations without repeating the code. Templates are like “macros”; wherever they are used, the code in them is inserted at that place. They also help to keep your html away from your javascript files, thereby increasing the readability and re-usability of your code. For a more comprehensive explanation see this blog post
The best resource to learn handlebars.js is their documentation
There is a course on Udemy that uses handlebarsjs and Node and Express and goes from pretty basic I think. This is it.
Related
I'd like to use polymer.dart to build a set of portable web components that can be embedded in any random html page (including pages outside of any dart project). The idea is that a customer could embed my polymer.dart elements on his html pages without the customer needing to create a dart application. I would think this would be an obvious and straightforward thing to do - but after going through many tutorials and instructional pages, and reading through lots of dart/polymer.dart documentation, I haven't found any explanation of how to go about this. Presumably the dart/polymer code would have to be compiled to javascript for inclusion on the customer's html page. Could someone comment on if this is possible, and if so, provide an explanation with examples of how to go about it? This dart/polymer.dart newbie would be grateful for any assistance.
I don't think this will work with Dart.
You need to run pub build over a Dart application to get a deployable result.
I guess this would work better with JavaScript Polymer elements.
There are plans to support this scenario but I guess it will still take a while.
I've had the chance to work with very different types of frameworks for web development. Somehow I can see that every framework tries to avoid me writing pure HTML code.
For example Spring has it's own tags, Struts comes with it's own tags also Zend and Codeigniter (PHP) have form helpers.
Does this mean I shouldn't just write HTML code myself or that it's not recommended? SHould I be using them? because they don't seem that intuitive, easy to manage and time saving as they intend.
You need to write your own HTML (and CSS) to define the overall structure and layout of your website design. Don't confuse this with time-saving features that eliminate the need to write repetitive HTML, such as form inputs and navigation menu items.
For example, under ASP.NET MVC you still need to get the bulk of your HTML into a MasterViewPage or Razor Layout, but when it comes to writing all of the form inputs you just need to put <%= Html.TextBoxFor( m => m.FirstName ) and it handles the rest, which saves you the trouble of writing boilerplate HTML for the <input /> element. It also helps avoid bugs (if you forget a name="" or `id=""`` attribute, for example, but in some frameworks it's essential to get reliable round-trip form data working.
I suggest you to manage your code by yourself if you don't have VERY good tools for generate it (for example Razor in ASP.NET MVC) which can do your code cleaner and more intuitive. In your case if You use Zend i suggest you to write your html in normal sites and only use generator for forms with Zenf_form. Becouse it is great.
Generated code services I have used generate ugly code that is hard to sift through at a later date.
writing the code and HTML yourself makes for a better structure and will not effect the way its run if that is what you are worried about and these languages are set to a standard.
Recommendation is to write the code where you can and generate code in areas you dont (or learn how to code it before you attempt it in test sheets).
I think it is a case by case basis.
These frameworks help you get rid of boilerplate code and write cleaner applications. You might also avoid some security problems by using them and you respect MVC.
There might be a performance penalty though so if you write a small application or you have certain requirements in speed you might be better without (some of) them.
The website I'm currently working on is supposed to be in multiple languages (4 in this case).
What's the "best" way to achieve this?
It seems like most people use a php table for it. Is this the "best" way right now?
Alas I only know some HTML and CSS, so my idea was to simply copy the whole website tree and make a seperate html tree for each language starting with index.html as the default language and three other trees starting with index_lang2.html, index_lang3.html, index_4.html.
On the index site you could switch the language and go down each seperate html tree.
Is this solution acceptable? I seems quite easy to generate but hard to maintain.
it depends on how much pages you have! There is no reason in making a language system if you only have 10 plain html pages and have no clue about php. And such systems are "only for" UI Elements and not for the real content if you plan to post information there...
If that are static pages, then using no such system is a nice solution!
But if you have more, then there are several solutions:
Take an existing Framework with language support
Write your own language class with vars on the different places
... there are for sure more possibilities, but nothing which comes in my mind :)
As already stated, I think as long as your site only has limited static HTML webpages then it's not worth trying to implement a fancy PHP solution (especially if you have to learn PHP to do so!)
I am pretty new to developing softwares and am intrigued by the huge world out there!! I have working knowledge of C/C++ and Java.. I was thinking of making an application that would convert a webpage to a pdf document.. I know there are many solutions available -- both online and offline..But I want to develop my own.. I googled but couldn't find anything that would help me get started..
I want to know how do we go about a conversion process?? How to get started?? What languages and technologies are pre-requisites for making a converter like this??
Thank You
So at least you need to get to the bottom to following specifications:
HTML specification
CSS specification
JavaScript specification
PDF specification
Moreover here are a lot of minor stuff such as Fonts, Decription/Encription algorithms and many many other minor but still necessary things.
I think you can imagine that this is quite a long way to get all this working. In fact, the complexity of such software is the reason why so many companies make money in this field.
Anyway, I'd suggest you to start from the simple things and grow your software gradually. Start with converting HTML to Image, because it is a bit simpler. Take and parse HTML, its CSS, its JavaScript. Clean HTML. Build DOM of the HTML document. Apply styles. Go thru the DOM and draw elements to the image.
Good luck!
I realize there have been a few other questions on this topic, and the general concensus is to use your language of choice to manipulate the XML. However, this solution does not quite fit my circumstances.
Firstly, the scope of the project:
We want to develop platform independent e-learning, currently, its a bunch of HTML pages but as they grow and develop they become hard to maintain.
We already have about 30 modules, with 10-30 HTML pages each, and this is growing all the time.
The idea:
Have an XML file(s) + Schema pre eLearning Module, then produce some XSLT files that process the XML into the eLearning modiles. XML to HTML via XSLT.
Why:
We would like the flexibilty to be able to easily reformat the content
I realize CSS is a viable alternative here, especially to visually alter the look'n'feel but we may need a little more power than this and go as far as restructuring the pages.
If we decide to alter the pages layout or functionality in anyway, im guessing altering the "shared" XSLT files would be easier than updating the HTML files.
Depending on some "parameters" we could output drastically different page layouts/structures, above and beyond what CSS can do.
Can XSLT take QueryString parameters? Not sure..
Now, all this has to be platform independent, and to be able to run "offline" i.e. without a server powering the HTML so server side technologies are out of the question (C#, PHP)
Negatives I've read so far for XSLT:
Overhead? Not exactly sure why...is it the compute power need to convert to HTML?
Difficult to learn
Better alternatives
Now, what I would like to know exactly is:
Are there actually any viable alternatives for this "offline"?
Am I going about it in the correct manner
Do you guys have any advice or alternatives.
EDIT:
With or without XSL, CSS and JQuery will be a very prominent part of the solution we
develop.
General tidy up (sloppy engrish!)
Using an XSLT scheme for this is legitimate. XSLT's are powerful if you develop the expertise.
Overhead: Yes, for large documents, a transform can take some seconds. Do a transformation on a large document called many times a minute can be a bad strategy. That won't be a big problem for you since you won't be doing these transforms on demand, just when you want to revise.
Difficult to learn. You can be productive with XSLT pretty soon, but beware: just when it seems XSLT's are getting easy, you'll be surprised by it getting tricky all of a sudden! What you think would be difficult can be easy, and vice versa. You'll might have to import or create some templates just to do some simple date formatting, for example. It's all doable though. Don't be afraid to learn how to do "templates".
Better alternatives. Yes, there are better alternatives, but they are platform specific. For example, I'm in .NET land, and I've dropped XSLTs in favor of manipulating our new XElements and such, and VB.NET embedded XML is very powerful and easy. But XSLT is still great when you want to avoid becoming dependent on a particular platform.
You're still going to use CSS as part of your strategy, right? Changing an XSLT to output styling consistently is better than doing it in 30 modules by hand, but a well-planned CSS stylesheet can still help simplify things (increase maintainability and flexibility).
In summary: To organized the layout/revision of static html pages, platform independent, for flexible distribution: yes, you have a good stategy, from what I can see. And expertise you develop in XSLT will be useful in the future, too. And after mastering XSLT, you'll really understand XML, which will be helpful forever.
XSLT is an ideal tool to use for generating HTML from XML documents in the circumstances you've described. The common complaint about XSLT's processing overhead - that it requires the entire source XML document to be loaded into memory - is really not relevant if you're using XSLT to generate static HTML pages, unless maybe you're generating hundreds of thousands of them.
(And in fact that complaint is really only relevant in cases where the source XML document is large. If you've built an architecture around dynamically generating HTML from large XML documents, choosing XSLT as your technology may be a mistake, but it is not the big mistake.)
You should of course also use CSS.
Separate your data from your presentation.
Offload presentation rendering to the browsers, use CSS and CSS "enhancers" like SASS, Less, etc.
Generate strict XHTML - can format with CSS, can parse with XML parsers, etc
Use JQuery like for interactivity
XSLT is quite heavyweight and won't scale well, whereas XHTML+XSS+JQuery is very well understood and lots of tools exist.
If you already know C# or VB.NET consider using LINQ to XML, the code will be longer, but it may be less pain to write and maintain for a none XSLT expert.
It all come down to how many XML transforms you will needed, just 1 or 2 then I would not spend the time learning XSLT.