Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

After studying HTML 5, I learnt that HTML is purely for defining semantics of data. And it has provided various tag for each purpose. Although we can create our own tags, can provide styling and it will work still we use standard tags because they are known at global level. And all search engines can understand them.

JS frameworks like AngularJS provide the way of creating own directive/tags. Which are non-standard tags.

Moreover, I believe that programming logic should be kept apart from HTML :ng-if, ng-repeat etc. It makes HTML page very difficult to understand by a pure UI designer. I would say these frameworks make a HTML page developer friendly not designer friendly.

If we put all the logic on a HTML page, there would not be any difference between a server side page & a HTML page.

I believe there should not be any non-standard tag and no programming logic (like conditional or looping statements) presents on HTML page. Instead JS should handle/control HTML from outside.

Please tell me if I am incorrect somewhere. Or give me some positives views So I can think about using such frameworks.

share|improve this question

closed as too broad by gnat, jwenting, GlenH7, Martijn Pieters, Bart van Ingen Schenau May 3 '14 at 14:19

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Imagine the case where the user in the browser is browsing data and they wish to drill down to see finer and finer views of some piece of data. It can often be advantageous to not serve a new page everytime they ask to see something else, but to instead issue an ajax call, receive some data, turn that data into the appropriate presentation and then add that to the current view in the browser. – jfriend00 May 1 '14 at 5:36
    
@jfriend00, loading data, doing some validation using ajax proves the importance of JS. They don't pollute HTML. Even if they add some elements to existing DOM they don't kick out HTML concepts. – Amit Gupta May 1 '14 at 5:39
    
Yes, that is my point. But, in my example, JS would be building HTML for presentation which you seemed to think was a bad thing. In some cases, a server-style template language might even be used in the client. I'm just trying to explain that life is not always as simple as plain HTML served from a server. – jfriend00 May 1 '14 at 5:45
    
nope even I support it. refreshing page or loading a separate page is always a bad idea. Like what we do with jQuery, we bind HTML elements using jQuery. Then we do a ajax request. makes a DOM entry and add it. Still it is good. But with angular we write logical and conditional statements along with HTML only, as we do with server side pages. – Amit Gupta May 1 '14 at 6:08
2  
This sounds like preaching. Also I disagree, XSLT is an example. – David Sergey May 1 '14 at 7:53

1 Answer 1

up vote 4 down vote accepted

Logic is often present in HTML templates on the client side because it makes sense to have it there. The logic contained within is not business logic, but simple conditionals and loops for controlling the output HTML, usually based on the data in question. There are couple of benefits to this.

First, including this logic in the view groups the structure of (part of) the page with logic which may augment it, creating a single point of change for the creation of the HTML output.

Secondly, including logic in the view makes the template generation easier to comprehend, as the generation logic is shown inline with the structure it is inserting elements in to. Take the following for example of structure and logic combined and compare it with the subsequent separated version. I think most developers would find the former much easier to comprehend.

In reference to the OPs point about the templates becoming difficult to understand for a "pure UI designer", I think the syntax of the average templating system is sufficiently English-like and readable that the average designer will be comfortable in at least reading the code and understanding it, if not modifying it. It's certainly more friendly for a designer than having separate code in a turing complete language they would need to maintain to update the templates.

Inline

<div id="myPagePart">
    <table>
        <thead>
            <tr><td>Header</td></tr>
        </thead>
        <tbody>
            {{ foreach item in collection }}
                <tr><td>{{item.name}}</td></tr>
            {{ endforeach}}
        </tbody>
</div>

Separated

<div id="myPagePart">
    <table>
        <thead>
            <tr><td>Header</td></tr>
        </thead>
        <tbody id="tablePart></tbody>
    </table>
</div>

var tableBody = document.getElementById("tablePart");
for(var i = 0; i <= data.length-1; i++){
    var item = data[i];
    var tr = document.createElement("tr");
    var td = document.createElement("td");
    td.innerText = item.name;
    tr.appendChild(td);
    tableBody.appendChild(tr);
}
share|improve this answer
    
+1, however one of the points of the OP was that although this might be a good idea for a developer, it makes the page harder to comprehend for a designer (his words). What do you think? – Paul Hiemstra May 1 '14 at 8:38
    
@PaulHiemstra Good point, I'll update my answer to address this – AndyBursh May 1 '14 at 8:44
    
Thanks @AndyBursh . it makes sens – Amit Gupta May 1 '14 at 11:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.