I am into this react.js and gatsby.js issue since a while.
But as a senior symfony developer I wonder if there are options
like TWIG even for gatsby sites?
Now I want to create sites with graphQl data and gatsby.
Is templating not possible with this new stack?
React is a JavaScript Library for building user interfaces, according to their website. It simply provides a clever wrapper UI to build component-based building blocks for an app. Once you grab content or/and data from somewhere—e.g. CMS, file system, Graphql DB, etc—you'll have to render them in a format you'd need. You could build a template-like structure via JSX, but I don't think React/Gatsby supports a templating engine like Twig.
If you're looking for a JavaScript-based static site generator, 11ty might be a good alternative, as it supports a whole bunch of templating languages. See this link.
Related
Not sure whether this is the best place for this question.
Is there a way to template a block of HTML code and then reuse it across multiple HTML files.
I know you can do it with PHP include.
But what is the industry standard now?
I have heard of Handlebars and Moustache. Are these the tools for this purpose?
And what is Jekyll and Middleman trying to do? What is static site generator?
Refer back to the above problem, which will solve my problem?
There are a number of templating engines these days that you can use. Mustache and Handlebars are both templating libraries with ports in different languages. There are a number of other templating engines: http://en.wikipedia.org/wiki/Comparison_of_web_template_engines
The library to use depends on your needs. Mustache emphasizes logic-less templates. This means that you should try and minimize the number of conditional statements (if/else) in your templates. Often, conditional if/else are used for determining what to render. Other libraries like Handlebars allow for logic. Choosing the right library will come down to the application requirements, how you want to use your templates, who will be maintaining them, and perhaps the language(s) that you are using for your application.
Jekyll, Middleman, Pelican and other static site generators use templating engines to help you generate a static site. When you write themes for these systems, you write the templates for the theme in the designated templating engine's syntax. For example, Jekyll uses the Liquid templating engine, and Pelican uses Jinja2. Static site generators started as a way to reduce the complexity of data management in blogs and websites. With some other blogging platforms, your posts and content would be stored in a database. This made migrating your work and backing it up a bit more complex, especially if you did not have in-depth technical knowledge of the blogging platform that you use. With static site generators, you can write all of your content in a text editor, using a simple file format like Markdown. To create a website, you just have to configure the system using a basic conf file, and follow the suggested project structure.
After writing your content, the static site generating system has the capability to automatically builds your website folder for you, making deployment easier. This is usually done through some kind of script/automation. All of your content is built into static .html and .css files (.js and image files as well, if you have them). This also can improve page load speed, since a static resource can be cached by the browser, and there are not as many operations on the server happening for each page request.
Using a static site generator will also help you configure how you manage content. A templating engine will be more for how you render content. Since rendering content is a subset of how you manage content, most static site generators will come packaged with a templating engine.
We are going to create some applications that will access the same api. We decided that the backed part will be developed in node.js and the database will be MySQL and maybe some parts mongoDB.
I have problem deciding about the front end of the web application that will be a website. Taking a look on this question: Separate REST JSON API server and client? we decided that fits better to us server side templating/rendering.
Do you think that using a PHP framework (like symfony, laravel etc) only for templating is good solution, or is it stupid to use a complete framework that offers a lot of features that we are not going to use only for templating? I was thinking to use twig that is only a template engine and try to fit backbone on it just to structure better the ajax calls to the RESTful API.
Do you have something different to suggest for server side rendering?
I have no experience at all, thats why i am writing to prevent taking bad decisions.
There are a bunch of awesome templating options for Node.JS! Here's a small list of some that I've used:
hogan (by twitter, feels like mustache)
jade (by tjholowaychuk, same code-machine behind express and a bunch of other awesome node projects)
ginger (by yours truly!)
swig (my personal favourite right now)
ejs (simple javascript-in-html thing, feels like php)
I like swig right now. It's basically what I wanted to build when I was working on ginger. It looks and feels a lot like django's templating system, which many popular template languages (twig, for example) have been inspired by.
I'm wondering when it is useful to use moustache.js (or something similar which do js templating), and when I can use backbone.js (which uses js templating inside it)
I've a web app with multiple pages, a json app, and the pages data are loaded via api calls, so I've tought about using moustache to clean up the rendering, but I'm wondering if backbone will improve something in my case
As already mentioned, they do serve completely difference purposes. Moustache being a templating engine, and Backbone bringing the MVC paradigm to Javascript. To quote from the Backbone homepage
When working on a web application that involves a lot of JavaScript, one of the first things you learn is to stop tying your data to the DOM. It's all too easy to create JavaScript applications that end up as tangled piles of jQuery selectors and callbacks, all trying frantically to keep data in sync between the HTML UI, your JavaScript logic, and the database on your server. For rich client-side applications, a more structured approach is often helpful.
So, if you find yourself writing a load of DOM manipulation calls etc. Or you simply prefer a structured approach to your code - you will find Backbone a godsend.
It is of course possible to use other templating solutions (other than the one bundled with Underscore) and integrate it into a client-side application created with Backbone.
Both cam be use together,
To build web application architecture you can use backbonejs.
and to render templates you can use mustachejs.
First of study basic knowledge about both.
You will well understand when to use what.
I searched for Java based web application frameworks the last few days. I have to build a Java EE backend and a HTML5/CSS3/JavaScript frontend which can be accessed with multi-touch capable devices. So I will need modern JavaScript frameworks like Sencha Touch.
My backend should be built upon with Java EE, Hibernate and MySQL. I have two kinds of data transfer: AJAX / JSON so the page does not need to be reloaded and pages and normal pages which reload the page by sending a form with POST (or do you think to have more the feeling as a application I should do all stuff with AJAX/JSON?).
I found several web application frameworks:
JavaSever Faces
Apache Wicket
Spring MVC
handle it only with jar files for JSON (and REST)
Google Web Toolkit
What do you think will fit best? Perhaps you can exclude one of them, that would also be great, so I can take a closer look at the remaining technologies.
Best Regards, Tim.
Interesting question.
Concerning exclusion: If you use a JS framework like Sencha Touch in the frontend I don't see the sense in using something like GWT which is for frontend-code generation.
I would probably stick with a more lightweight framework like http://www.playframework.org/.
You get your data from the backend and then hand it via JSON over to your frontend code i.e. sencha, sproutcore, cappuccino, gwt or what you choose to use.
Let me know what you choose :-)
My company builds websites for membership-based associations. We currently use custom DLL's (written in CodeGear Delphi) which interact with a SQL Server database and use a custom HTML-based template language. Basically we build templates in HTML / CSS / Javscript with the dynamic parts being generated by tags in the format <#TAG NAME>.
I've been building all the templates for our clients using Dreamweaver, but my boss wants me to create a web tool which our clients can use to visually build templates themselves in our format, without needing to do actual HTML coding. For example, they would go to our site and say "create profile update form" which would generate an HTML skeleton, then they could select functions such as "add form field" to generate the correct HTML for that field based on the options they enter. The template would then be saved to the web server as an HTML file (or to the database as a blob) and used by the DLL's to generate pages on the site. They should also be able to re-visit the existing templates to edit them, and manually edit the HTML if necessary for advanced customization.
Obviously there are a lot of ways to go about this. I'd like suggestions on a server-side language (and hopefully associated libraries / modules) which is capable of building and parsing HTML documents and writing these to the file system. The tool needs to be IIS compatible, and preferably in a C-style syntax. I'm very proficient in Javascript and Perl, slightly less so in C++ and Java, and have no experience with PHP, Ruby, or Python (though I'm willing to put in the time to learn if they are the best tool for the job!).
Thanks for your suggestions!
Have you seen TinyMCE? It lacks form editing, but you could easily build plugins to customize it to your needs and create the front-end around it. For server side you can use any language that you like. Basically all you would need to do is to save the HTML templates that your customers would create to a database.
I used mobirise4 and it works for me, there are lots of templates to start with, even some components, and BootStrap studio its the best payed desktop application, you can literally build a website with some drag & drops, it lets you to edit code too.