Answers.Body: <p>Answer:<br>
  In order to render all the scripts in your registered assetbundles you need to call this function</p>
  
  <pre><code>{{ endBody() }}
  </code></pre>
  
  <p>somewhere in your page (preferred at the end of the body) </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-27T06:31:43.880Z
Answers.LastActivityDate: 2017-10-27T06:31:43.880Z
Answers.UserDisplayName: Robin Schambach
Answers.Body: <p>This question is related to YII2 Advanced Template:
  <a href="https://github.com/yiisoft/yii2-app-advanced/blob/master/frontend/views/layouts/main.php" rel="nofollow noreferrer">https://github.com/yiisoft/yii2-app-advanced/blob/master/frontend/views/layouts/main.php</a></p>
  
  <p>Frontend Twig layout template</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;  
      {% block head %}
      &lt;meta charset="UTF-8"/&gt;
      &lt;title&gt;Title&lt;/title&gt;
      {{ head() }} {# css from AssetBundle #}
      {# {% do view.registerCssFile( "url") %} #} {# Your custom css #}
      {% endblock %}
  &lt;/head&gt;
  &lt;body&gt;
      {{ beginBody() }} {# js from AssetBundle #}
          {% block content %} 
              Hello world! 
          {% endblock %}
      {# {% do view.registerJsFile( "url") %} #}{# Your custom js #}
      {{ endBody() }} {# js from AssetBundle #}
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>In your plugin Controller use renderPageTemplate not only renderTemplate. The renderPageTemplate envelops renderTemplate using beginPage() and endPage(), see craft\web\View.php </p>
  
  <p>The combination renderTemplate and {{endBody}} only generates in HTML <code>&lt;!CDATA ...&gt;</code> lines.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-25T21:02:29.443Z
Answers.LastActivityDate: 2018-09-25T21:23:30.473Z
Answers.LastEditDate: 2018-09-25T21:23:30.473Z
Answers.UserDisplayName: lenka
Body: <p>How can I register an assetbundle in a frontend template?
  This is my bundle</p>
  
  <pre><code>namespace secondred\formbuilder\assetbundles\Formbuilder;
  
  use Craft;
  use craft\web\AssetBundle;
  use craft\web\assets\cp\CpAsset;
  
  class FormbuilderAsset extends AssetBundle
  {
      // Public Methods
      // =========================================================================
  
      /**
       * Initializes the bundle.
       */
      public function init()
      {
          // define the path that your publishable resources live
          $this-&gt;sourcePath = "@secondred/formbuilder/assetbundles/formbuilder/dist";
  
          // define the dependencies
          $this-&gt;depends = [
              CpAsset::class,
          ];
  
          // define the relative path to CSS/JS files that should be registered with the page
          // when this asset bundle is registered
          $this-&gt;js = [
              'js/Formbuilder.js',
          ];
  
          $this-&gt;css = [
              'css/Formbuilder.css',
          ];
  
          parent::init();
      }
  }
  </code></pre>
  
  <p>And I can register it with in my controller without any problems<br>
  <code>$this-&gt;view-&gt;registerAssetBundle(FormbuilderAsset::class);</code></p>
  
  <p>But when I do </p>
  
  <pre><code>{% do view.registerAssetBundle("secondred\\formbuilder\\assetbundles\\formbuilder\\FormbuilderAsset") %}
  </code></pre>
  
  <p>nothing happens.. no request, no error, nothing in network tab and no html is added to the page</p>
  
  <p><strong>Update</strong>
  <br>I found the solution. If you are in a frontend ressource you need to call the <code>{{ endBody() }}</code> method in order to get the bundles</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-25T23:35:35.830Z
Comments.Text: A case-sensitivity issue maybe?  Try `{% do view.registerAssetBundle("secondred\\formbuilder\\assetbundles\\Formbuilder\\FormbuilderAsset") %}`
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-26T09:19:58.943Z
Comments.Text: Thanks Brad, but I found the solution myself.. it was because I didn't call the `{{ endBody() }}` in my frontend template. Maybe it is worth mentioning in the documents? https://github.com/craftcms/docs/blob/master/en/asset-bundles.md
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-26T23:04:39.770Z
Comments.Text: Yup... added a note to update it.  Would you mind adding that as an official answer?
Comments.UserDisplayName: Brad Bell
Tags: <templating><craft3>
Title: Register Assetbundle in frontend template
ThreadText: # Register Assetbundle in frontend template
  
  (Asked by: username_0 on 2017-10-24)
  
  How can I register an assetbundle in a frontend template?
  This is my bundle
  
  ```
  namespace secondred\formbuilder\assetbundles\Formbuilder;
  
  use Craft;
  use craft\web\AssetBundle;
  use craft\web\assets\cp\CpAsset;
  
  class FormbuilderAsset extends AssetBundle
  {
      // Public Methods
      // =========================================================================
  
      /**
       * Initializes the bundle.
       */
      public function init()
      {
          // define the path that your publishable resources live
          $this->sourcePath = "@secondred/formbuilder/assetbundles/formbuilder/dist";
  
          // define the dependencies
          $this->depends = [
              CpAsset::class,
          ];
  
          // define the relative path to CSS/JS files that should be registered with the page
          // when this asset bundle is registered
          $this->js = [
              'js/Formbuilder.js',
          ];
  
          $this->css = [
              'css/Formbuilder.css',
          ];
  
          parent::init();
      }
  }
  
  ```
  
  And I can register it with in my controller without any problems  
  `$this->view->registerAssetBundle(FormbuilderAsset::class);`
  
  But when I do
  
  ```
  {% do view.registerAssetBundle("secondred\\formbuilder\\assetbundles\\formbuilder\\FormbuilderAsset") %}
  
  ```
  
  nothing happens.. no request, no error, nothing in network tab and no html is added to the page
  
  **Update**
    
  I found the solution. If you are in a frontend ressource you need to call the `{{ endBody() }}` method in order to get the bundles
  
  **Tags:** templating, craft3
  
  > **Comments:**
  > **username_1**: A case-sensitivity issue maybe?  Try `{% do view.registerAssetBundle("secondred\\formbuilder\\assetbundles\\Formbuilder\\FormbuilderAsset") %}`  
  > **username_0**: Thanks username_1, but I found the solution myself.. it was because I didn't call the `{{ endBody() }}` in my frontend template. Maybe it is worth mentioning in the documents? https://github.com/craftcms/docs/blob/master/en/asset-bundles.md  
  > **username_1**: Yup... added a note to update it.  Would you mind adding that as an official answer?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2017-10-27. Score: 0 | Accepted answer
  
  Answer:  
  In order to render all the scripts in your registered assetbundles you need to call this function
  
  ```
  {{ endBody() }}
  
  ```
  
  somewhere in your page (preferred at the end of the body)
  
  
  ---
  
  ### Answer by username_2 on 2018-09-25. Score: 0
  
  This question is related to YII2 Advanced Template:
  <https://github.com/yiisoft/yii2-app-advanced/blob/master/frontend/views/layouts/main.php>
  
  Frontend Twig layout template
  
  ```
  <!DOCTYPE html>
  <html>
  <head>  
      {% block head %}
      <meta charset="UTF-8"/>
      <title>Title</title>
      {{ head() }} {# css from AssetBundle #}
      {# {% do view.registerCssFile( "url") %} #} {# Your custom css #}
      {% endblock %}
  </head>
  <body>
      {{ beginBody() }} {# js from AssetBundle #}
          {% block content %} 
              Hello world! 
          {% endblock %}
      {# {% do view.registerJsFile( "url") %} #}{# Your custom js #}
      {{ endBody() }} {# js from AssetBundle #}
  </body>
  </html>
  
  ```
  
  In your plugin Controller use renderPageTemplate not only renderTemplate. The renderPageTemplate envelops renderTemplate using beginPage() and endPage(), see craft\web\View.php
  
  The combination renderTemplate and {{endBody}} only generates in HTML `<!CDATA ...>` lines.
  
  
  ---
  
  