Excuse me, Master, a page element displays the content of different pages according to different roles. How can we judge it without using the background language PHP? For example, if there is a delete button, the teacher has it but the students don’t. How to implement it without using PHP or other backend? Template engine?
Generally speaking, get or set this [status information] from the ajax interface/HTML template/localStorage, and then do the corresponding processing in JS.
According to whether your current user is a student or a teacher, just use js to judge and display accordingly
If you don’t rely on PHP templates, I personally recommend using the front-end angularjs. Although vue.js also has template judgment, the angularjs style will be more biased towards TP YII and other PHP templates. Of course, you can limit the html display through JS, but the more tags are restricted, the more cumbersome the js becomes
Method 1: Templates are of course possible
Method 2: When returning to the page, it is also retrieved. Just add an ajax request code to the html header. A small amount of code has little impact on performance. The identity of the teacher or student, Then use js to make judgments and operate the dom. One thing to note here is that if the requirement involves a large number of dom operations, do not use this solution. Optimizing the dom yourself is a troublesome thing.
Method 3: Use a framework such as react to implement it, extract the html elements that need to be changed, and abstract them into components, which is also very efficient. For students who have front-end knowledge, it is recommended to understand the Yiha framework.
First understand how you judge the two roles of teacher and student, and secondly, you can handle the buttons differently based on this judgment
First, the template engine can meet your needs, but you need to know the syntax corresponding to the template
Second, if you use js to control, you must first understand how you get the identity. Is there a value in the page itself, or do you need to use ajax to get it. After getting the value, write an if to perform the corresponding operation on the element
Determine the user type when the page is loaded and load different modules as needed
iframe loads different iframes to display single-page applications according to different conditions. . . . .