faloposter.blogg.se

Pug template mixin
Pug template mixin









pug template mixin

Below is an example showing how to include the form in my hello.pug page. I will be using the page examples from my previous post to illustrate how things fit together. Rather than writing that out (or copying and pasting) everywhere I want it, I can include it. I have created a simple form with a name input, a message input, and a submit button. includes/form.pugįorm(action='/action-goes-here' method='post') The code below shows what’s in my form template. In our form example, the form code would just be standard Pug templating. Includes allow you to write some static code (no dynamic data) and put it wherever you want in the templates. This is exactly the reason Pug gives us the ability to use includes. Again, that leads to issues with having to update something in multiple locations. If you wanted that on two different pages, you’d have to create the form manually on each page even though they’re exactly the same. Imagine you’ve got a piece of your site that will be used in various places on your site, such as a contact form. These concepts also fall into the DRY category and can help make your life as a developer much easier. Now that we’ve covered templating, logic, and layouts, it’s time to cover the last major piece of Pug: includes and mixins. Using the Pug Templating Engine Part 4 – Includes & Mixins











Pug template mixin