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

Defining subtemplates within a template ? #123

Open
albert-kam opened this issue Jan 1, 2020 · 2 comments
Open

Defining subtemplates within a template ? #123

albert-kam opened this issue Jan 1, 2020 · 2 comments

Comments

@albert-kam
Copy link

Hi, im currently learning rocker, and very much impressed with it at the moment.

I'm just curious whether it's possible to define a subtemplate within a template, for the sake of visibility and without having to switching opened file.

The use case is simple, looping to create a html table, with each row rendering moved to a single subtemplate. Pretty much like refactoring a method to another method to avoid a big fat method.

Thank you !

@albert-kam
Copy link
Author

This not to add more complexities or logics, but rather breaking down html structure rendering into own methods, so it's clearer which method/subtemplate to check when we need to.

For me it's easier to read method names before going to the method to check the impl details (below is not method names yet, only prototype names, but the reasoning is the same):

render page
  loop render table
    loop render subtable
  render global error message
  render form
    render input text
    render input email
    render submit button

For rendering form and it's inputs, i could place them into their own reusable templates.

But for table and subtables, whose rendering logic might be a bit long - making it hard to mental model which is doing what, and since its only used for this template: breaking it down within the same template means easier to read and go deep as needed.

@jjlauer
Copy link
Member

jjlauer commented Jan 7, 2020

@albert-kam I'm certainly open to the idea and thought of that myself when originally developing the framework. I ended up punting on the concept due to the additional parsing rules and code generation necessary to get it to work. In my own projects, I just place these templates in their own template file and reuse them that way. If you wanted to take a stab at implementing it, I'd be very open to a PR that did that.

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