jeudi 28 septembre 2017

How to dynamically choose what html template to render. What type of design pattern is it?

Don't be confused with 'template type' definition. It is not related to angular. It only means that it's a template for concrete page, e.g. HomePageTemplateOne, HomePageTemplateTwo, etc

I have a home page, which I want to make dynamic, depending on what type of theme(template type) I requested for

Let me explain in details: I have one type of template for home page, which has title with orange background, 600px width logo, and footer with text: "This is footer." And data which I get from server would be:

{ 
   title: "Title", 
   titleBackground: "green", 
   logo: "someUrlForLogo",
   logoWidth: "600px",
   footer: "This is footer"
   templateType: "SimpleTemplate"
}

Also I want to have another theme(template type) for home page. Which data would be:

{ 
   title: "Title", 
   title-background: "orange", 
   topLogo: "someUrlForLogo",
   leftSideLogo: "antoherUrlForLogo",
   topLogoWidth: "600px",
   leftLogoWidth: "300px "
   description: "Here is my description",
   footerImagesUrls: [ "firstUrl", "secondUrl", "thirdUrl" ],
   footerImagesSize: "100px"
   templateType: "ComplexTemplate"
}

If I make check for every property in data - it will not be scalable. Something like:

switch(data.TemplateType) {
   case TemplateType.Simple {
      // renderSimpeTypeTemplateView with data
      break;
   },
   case TemplateType.Complex {
      // renderSimpeTypeTemplateView with data
  }
}

And could you please tell me what type of design pattern it would be

Thanx

Aucun commentaire:

Enregistrer un commentaire