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

HTML

Vijayalaxmi vastrad
Vijayalaxmi vastrad
2,789 Points

how to create reusable block of code in html

i am creating custom vending machine app, so clients can change tr content as per requirement, in order to do that i need to use reusable html code, how to do that?

3 Answers

Tobias Graefe
Tobias Graefe
11,934 Points

You could use JavaScript to insert a reusable HTML Block in your DOM. With that you are even able to change the content, while the markup has the same structure.

Vijayalaxmi vastrad
Vijayalaxmi vastrad
2,789 Points

Thank you, i have same owl carousel in multiple pages, its 63 line of html code how can make it writes once use multiple times in multiple pages

Steven Parker
Steven Parker
231,248 Points

While JavaScript could certainly be used to change the page dynamically while it is being displayed, what you describe might be more of a job for the server code.

The server side of the app could be designed to allow changes to be made to the pages before they are initially displayed to the end user. Web apps typically use parameters taken from a database to construct the pages to be displayed, and the data can be configured by the client at the server or through a separate customizing app.