dimanche 28 avril 2019

How to set web template variable to a dynamic html&golang code?

I have two web page on golang and I want to embed this pages codes to variable (defined in templates/main.html) being with dynamic according to the coming requests.

For example if the guest enter the userregister page I want to the variable will be userregister codes otherwise userprofile codes.

templates/userregister.html page codes;


   ...
   
   ...


templates/userprofile.html page codes;


   ...
   
   ...


templates/main.html;


<!DOCTYPE html>
<html lang="tr">
    
    <body>
        <div class="container-fluid">
            
            <div class="row">
                <nav class="col-12 col-md-2 p-0">
                    
                </nav>
                <div class="container-fluid col-12 col-md-10">


                    


                </div>
            </div>
            
        </div>
    </body>
</html>


The userregister page controller;

func PgUserRegister(c *gin.Context) {
    c.HTML(http.StatusOK,"main", gin.H{
        "pgETitle": "User Register page",
        "specialmessage": "You are on the userregister page.",

        "content": template.ParseFiles("userregister.html"),
    })
}

The userprofile page controller;

func PgUserProfile(c *gin.Context) {
    c.HTML(http.StatusOK,"main", gin.H{
        "pgETitle": "User Profile",
        "specialmessage": "You are on the userprofile page.",

        "content": template.ParseFiles("userprofile.html"),
    })
}




Aucun commentaire:

Enregistrer un commentaire