Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Templates to be more modular #37

Open
Zauberfisch opened this issue Mar 24, 2014 · 2 comments
Open

Refactor Templates to be more modular #37

Zauberfisch opened this issue Mar 24, 2014 · 2 comments

Comments

@Zauberfisch
Copy link
Contributor

Currently, many of the SwipeStripe modules just overwrite existing templates, this works well until 2 modules try to overwrite the same file, and one of the modules will not be used.
It also means that the integrity of SwipeStripe + modules is harder to keep clean, because if we change something in a template, we have to change it in all modules that overwrite it as well.

I would like to have a more $Layout style approach, to have a base template, and have variables at places where modules can add their content.


An example:

the Addresses Module overwrites the whole AccountPage.ss template to add the Address information to the Account page.
It should be possible to add an Extension to AccountPage, with for example a hook called insertBeforeContent or insertBeforeOrders, which can return a string that will be injected in the template before the Orders or the Content. (just a starting point, I am sure we will come up with a nicer solution)

@frankmullenger
Copy link
Contributor

The idea was to use the base functionality of SilverStripe where possible. So I was hoping that people would use the templates bundled with the modules as a guide rather than altering the template in the module directly (and manage the module dependency with composer).

It's really my intention that devs copy the templates into their theme folder which then takes precedence, that way they can alter the layout etc. as they like. It isn't ideal that some modules' templates override the SwipeStripe module templates but that is core functionality really.

I'm not so keen on adding methods in the PHP for managing the template layout really. Perhaps we could make it clearer for devs to copy the template files into their theme folder or even a task that will do so for them?

@Zauberfisch
Copy link
Contributor Author

I dislike that idea.
because it is unnecessary, my rule over the thumb is not to overwrite template files of modules unless I really have to. The reason for this is to keep updating easier.
If you have overwritten all templates, and you then upgrade a module, you would need to go through all templates and see if something has changed, and that can be pretty annoying.

The 2nd reason is because it makes the point of entry a lot higher. lets think of someone that has not so much experience with SilverStripe, he will most likely have his hands full trying to understand how the other things work, if we force him to also overwrite all templates, he is never going to go with SwipeStripe, because its just out of his scope.


perhaps it becomes more clear if I provide a code example; again, the addresses module:

AddressesAccountPageExtensions extends DataExtension {
    public function insertBeforeOrders() {
        return $this->owner->renderWith('AccountPageAdresses');
    }
}

but that's just one idea of implementation, the are other alternatives like introduce a config option that contains a list of templates or something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants