Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Why is there more than than one ERB file?

Why did we create a second ERB file?

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

I'm not exactly sure what you are referring to here, but yes, a Sinatra app will often have multiple ERB files associated with it-- each ERB file is a "view"

ERB, which you already know means "Embedded Ruby" and is similar to other templating languages in web frameworks like Flask's Jinja2 and Django's template language which combine HTML and a context-aware subset of the programming language.

Typically, each "view" will have an ERB file which contains a mixture of HTML and embedded Ruby code. Ruby and ERB are so flexible that you could easily have two or more ERB files associated with a view. For example, depending on a user login type you could show either a "normal user template" or an "administrator template"

Another way to use multiple ERB files is to use the "sub-templating" approach. Where one ERB file will include a second ERB file.

https://www.ruby-forum.com/t/subtemplating-with-erb/121510

WOW thanks for letting me know!