MyBB Community Forums

Full Version: Code Snippets
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am wondering how to insert large amounts of HTML into multiple templates.

For example, in the index template,
the header HTML is called up by using the snippet {$header}.

The same goes for other snippets such as {$footer}, {$forums}, and {$boardstats}.

All these {$} snippets contain the real HTML code that will then replace the snippet upon the page load.

How do I create snippets of my own? I'd like to place chunks of code on different templates without having to paste in the entire lengthy code, and use a snippet such as {$chatbox} or {$sidebar} instead.

As of right now, I have to edit all affected templates and replace stuff there. I'd like to just edit my HTML in one place instead. I'd just have to replace the chatbox template or the sidebar template and wherever {$chatbox} or {$sidebar} is called up, the changes will be automatically made.

I see plugins that create their own {$} snippet for the same reason. My question is.. is there a way to achieve this without the creation of a plugin?
(2013-04-13, 06:29 PM)jackrower Wrote: [ -> ]I see plugins that create their own {$} snippet for the same reason. My question is.. is there a way to achieve this without the creation of a plugin?

Only with core edits. These "snippets" are PHP variables. You need to create them one way or another.
You can achieve this using the Hooks plugin.
Create one with the hook global_start.
(2013-04-13, 06:33 PM)Nathan Malcolm Wrote: [ -> ]Only with core edits. These "snippets" are PHP variables. You need to create them one way or another.
ah, I was wondering what the proper term for them was. Thanks, I was able to look up more info about them. And I now see that they are defined in the different PHP files.

(2013-04-13, 06:50 PM)JordanMussi Wrote: [ -> ]You can achieve this using the Hooks plugin.
Create one with the hook global_start.
I'm thoroughly confused by this, how exactly would I use this plugin to create custom snippets? This does look real promising though. Thanks for helping out a newbie!
You would use this code:
eval("\$template = \"".$templates->get("new_template")."\";");
template is the {$template} variable that can be used in templates.
new_template is the template that is included where the {$template} variable is added.
Sorry if that is slightly confusing.