Pergunta

Actually, I need some ideas on allowing different templates, in Play app, my problem or requirement goes like:

  • When users register to my app, I create a different webpage for them, and also allow them to choose a template/design( the webpage is actually a different Play app).

Is there a standard way (work-flow) to generate templates dynamically without creating separate resources( css,html files for each individual template).

Sorry, couldn't provide full specifics. Any suggestion is welcome, thank you.

Foi útil?

Solução 2

Thank you Biesior for your helpful insights, I guess i'll be looking forward to your first two suggestions since using Jsoup seems a bit overkill for my skill in Play2/scala (just started) and also, for those stumbling upon this post, there are other helpful SO posts too scratching around the similar issues:

Outras dicas

Nope, there isn't any solution in Play, anyway depends what do you mean by different template:

  • If it's only about changing 'look & feel' you can achieve that easily by replacing CSS only.
  • If you plan to make quite different set of data per template you will need to use custom markers in the template records (file or DB stored) and process them yourself.

Second solution will be much more advanced task so you need spend much more time on this. Here with help comes some HTML parser i.e.: jsoup (Java) which will allow you to build your custom templating engine.

Free concept:

You can just store template's HTML code i.e.: in DB (for easier modification without app's redeploying), then you can just use jsoup for finding your elements and replacing it with rendered parts like, menus, breadcrumbs, contents, etc. i.e. replace:

<my-breadcrumbs />
<my-menu data-style="vertical" />
<my-content data-column="left" />

etc.

TIP: if you ever used for an instance TYPO3, it's similar concept of marks and/or subparts, just jsoup helps here parsing the HTML

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top