Include other Twig Templates

Video loading...

Transcript language code: 

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:02
    with Leanna Pelham
  • 0:08
    Using a base layout is very common
  • 0:10
    and we've just mastered that.
  • 0:13
    Now, suppose that we have a small sales banner that we want
  • 0:15
    to include on both the home page and the contact page.
  • 0:18
    Because penguins care about saving some krill, too.
  • 0:23
    If we want it on every page, then we should put it in our layout.
  • 0:27
    But pretend for now that we only need it on these two pages.
  • 0:31
    To avoid duplication, create a new template
  • 0:34
    that will hold the sales banner.
Loading ...

Include Other Twig Templates


Using a base layout is very common, and we’ve implemented that in the previous tutorial. Sometimes you also need to include some other templates on only select pages. In this tutorial you are going to add a sales banner to the pages using the include function, and working with the variables we can pass there.

Log in or sign up to download companion files.
Additional resources: 

Be sure to check the documentation for the version of Twig in your codebase for the correct syntax and usage.

  • Documentation for include function: 1.x | 2.x | 3.x