Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Creating Assets to use in Smarty

I looked through the forums and didn't find a definite answer on how and where to create an asset such as {asset name="Content"}

To keep it simple I just want to create an asset that displays a piece of text such as "Hello World".
In my smarty template I want to put this: {asset name="HelloWorld"}

How do I achieve this?
I read somewhere I need to do this: Gdn::controller()->addAsset();

But where do I create the file? What parameters go into that method?



  • Options
    hgtonighthgtonight ∞ · New Moderator

    Vanilla provides a few asset containers out of the box: head, panel, content, and foot. You can add any asset container you want to your smarty template using the syntax you used.

    You can add an asset (which is just a string) directly to a specific container via the Gdn_Controller::addAsset($container, $asset, $name) method.

    Garden also provides a module system to simplify this process. Once your module targets that asset container, you just need to add it to the controller you want it to show on. A simple module that targets a custom asset is shown here:

    class HelloModule extends Gdn_Module {
      public function AssetTarget() {
        return 'HelloWorld';
      public function ToString() {
        return "Hello world, I must be dreaming."

    Sample code that hooks into every controller and adds the module:

    public function base_render_before($sender) {
      $module = new HelloModule();

    If you have questions on how to create a plugin, I suggest reading the documentation here:

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Sign In or Register to comment.