If you have a view file which you want to re-use for different pages which have, for example, slightly different page headings, is there a 'best approach' of the three below? (Considering separation of concerns, business/presentation logic, etc.)
As an example, if I have the same ‘What is your address’ page but for a number of different account types e.g. charity account, personal account, business account, etc. which need different page headings respectively.
(a) Pass in the specific page heading in the controllers
- CharityAccountController:
return h.view({ pageHeading: "What is the charity's registered address?"}) - PersonalAccountController:
return h.view({ pageHeading: "What is your address?"}) - View file:
<pageHeading>{{ pageHeading }}</pageHeading>
(b) Pass in an account type flag in the controller and have some conditional logic in the view to set the heading:
- CharityAccountController:
return h.view({ isCharityAccount: true }) - PersonalAccountController:
return h.view({ isPersonalAccount: true }) - View file:
<pageHeading> { if isCharityAccount } What is the charity's registered address? { else if isPersonalAccount } What is your address? { else … } </pageHeading>
(c) Use separate view files for each page, abstracting as much as possible to common 'partials'
There may also be other page elements specific to account types e.g. hint text, validation error messages. And certain elements may need to be shown/hidden depending on the account type.