How to render plugin's template in other template?

How to render plugin's template in other template?

by Paul K -
Number of replies: 3

Hello,

I created a new plugin. It has "templates" dir with "template.mustache" file. I can include this template in another template via {{> auth_myplugin/template }}. But what with template context and variables for that template? 

I don't want create a new page and render it. All I want is pass the variables from PHP to my template and display it in sidebar of my theme.

Average of ratings: -
In reply to Paul K

Re: How to render plugin's template in other template?

by Paul K -
Anyone?
In reply to Paul K

Re: How to render plugin's template in other template?

by Andreas Grabs -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Translators

Hi Paul,

you can override templates in your theme by adding a folder with the component name in your templates folder. There you put the template you want to override.

Example: You want to overriede the template "xyz" from "block_xyz".

  1. Create a folder in your theme "templates/block_xyz"
  2. Copy the original template "blocks/xyz/templates/xyz.mustache" into your new folder.
  3. Change the template as you wish.

The data will be passed automatically to your template every time the template is used.

Best regards
Andreas