If any of the info on this website was useful for your projects or made your head spin with creative ideas, and you would like to share a token of your appreciation- a donation would be massively appreciated!

Your donation will go to my Robotics Fund, straight towards more sensors, actuators, books, and journeys. It takes a lot to continue building these robots, and I’m really thankful of everyone who helps encourage me along the way.



“A wise robot once said to me through Serial.println- that robots teach us about ourselves.”

php include in .tpl for Vanilla theme using plugin

When creating the RoboBrrd forums a few days ago, I wanted the theme to have the same header and footer as the rest of the site. The way the site is ‘designed’ is that the header and footer can be included via a php include. This is in order for the main website to be run from a Twitter Bootstrap framework, the blog from WordPress, and the forum from Vanilla. Switching between these should not be interruptive to the visitor.

Vanilla themes are different though. They use a .tpl file, which is as it sounds, a template file. Smarty, which is the template engine is able to parse through this, and perform its template magic.

There are two ways that php includes could be done, however do not work with Vanilla. These are:

  1. {literal} your literal content here {/literal}
  2. {php} your php code here {/php}

The literal tag way does not work. Not quite sure why, but I spent the time with it and it doesn’t work.

The php tag way does not work because the php tag in Smarty was deprecated.

Instead, the best way to do this is with a custom function! This way works, and it is quite fun.

Here is how to do it:

  1. Navigate to /vanilla/plugins — where ‘vanilla’ is whatever folder name your forum install is in
  2. Create a new file named: function.myinclude.php
  3. Add in this php code below, where the include path is whatever path to the php file you want to include (such as header.php or footer.php)
    1. <?php
    2. function smarty_function_myinclude($params, $smarty) {
    3.         include("path.php");
    4. }
    5. ?>
  4. Save it. Now navigate to your .tpl file for your theme. Example: /vanilla/themes/BrandFriendly/views/default.master.tpl
  5. Wherever you want your php include to be, add this line to your tpl file:
    1. {myinclude}
  6. Save it and test it. It worked for me, so hopefully it works for you too!

Those steps are all that is needed to get your lovely headers and footers added in. To create multiple of these plugins, be sure to rename the filename as well as the function name, and the tag name as well. For example, we used the name ‘myinclude’, and if you wanted you could create a different one like ‘leadsolder’, by renaming the places where it says ‘myinclude’, in the file name, function name, and tag in the tpl file.

Well, I hope this will help someone on the internet somewhere! It took a while for me to figure out.

Also yes, the RoboBrrd forums are open! There isn’t much to discuss yet, but hopefully soon there will be! :)

2 CommentsLeave a Comment

  • Tim

    3 years ago

    Oh my god why isn’t this on the first page of Google search results. This was exactly what I needed! Thanks heaps.

  • sergio

    2 years ago

    I can’t get this to work,
    are we supposed to create the file function.myinclude.php on plugins?

    the tag is not working :(

Leave a CommentPlease be polite. We appreciate that.

Your Comment