Answers.Body: <p>In your plugin's main file init method setup your template hook. In this hook you can call a service method to return your rendered HTML.</p>
  
  <pre><code>public function init()
      {
          craft()-&gt;templates-&gt;hook('video.slider', function(&amp;$context)
          {
              $response = craft()-&gt;pluginname_service-&gt;serviceMethod();
              return $response;
          });
      }
  </code></pre>
  
  <p>In your plugin's service file create a method to return your rendered HTML. </p>
  
  <pre><code>function serviceMethod() 
      {   
  
          $oldPath = craft()-&gt;path-&gt;getTemplatesPath();
  
          $newPath = craft()-&gt;path-&gt;getPluginsPath().'path/templates/folder';
          craft()-&gt;path-&gt;setTemplatesPath($newPath);
  
          $templateName = '_templatename';
  
          //If you need to get data from somewhere else to pass to the template
          $htmlData = craft()-&gt;plugin_service-&gt;serviceMethod();
  
          $htmlResponse = craft()-&gt;templates-&gt;render($templateName, array("variableName" =&gt; $htmlData));
  
          //reset path
          craft()-&gt;path-&gt;setTemplatesPath($oldPath);
  
          return $htmlResponse;
      }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-29T04:04:11.433Z
Answers.LastActivityDate: 2016-11-29T04:04:11.433Z
Answers.UserDisplayName: a-am
Body: <p>I'm trying to render my HTML, CSS, JavaScript with the use of template hooks from a plugin.</p>
  
  <pre><code>{% hook 'video.slider' %}
  </code></pre>
  
  <p>Is it possible? If it is, can you give some snippet?</p>
  
Tags: <plugin-development>
Title: How to add HTML, CSS, JavaScript on the front-end using a template hook in a plugin?
ThreadText: # How to add HTML, CSS, JavaScript on the front-end using a template hook in a plugin?
  
  (Asked by: username_0 on 2016-11-25)
  
  I'm trying to render my HTML, CSS, JavaScript with the use of template hooks from a plugin.
  
  ```
  {% hook 'video.slider' %}
  
  ```
  
  Is it possible? If it is, can you give some snippet?
  
  **Tags:** plugin-development
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-11-29. Score: 6 | Accepted answer
  
  In your plugin's main file init method setup your template hook. In this hook you can call a service method to return your rendered HTML.
  
  ```
  public function init()
      {
          craft()->templates->hook('video.slider', function(&$context)
          {
              $response = craft()->pluginname_service->serviceMethod();
              return $response;
          });
      }
  
  ```
  
  In your plugin's service file create a method to return your rendered HTML.
  
  ```
  function serviceMethod() 
      {   
  
          $oldPath = craft()->path->getTemplatesPath();
  
          $newPath = craft()->path->getPluginsPath().'path/templates/folder';
          craft()->path->setTemplatesPath($newPath);
  
          $templateName = '_templatename';
  
          //If you need to get data from somewhere else to pass to the template
          $htmlData = craft()->plugin_service->serviceMethod();
  
          $htmlResponse = craft()->templates->render($templateName, array("variableName" => $htmlData));
  
          //reset path
          craft()->path->setTemplatesPath($oldPath);
  
          return $htmlResponse;
      }
  
  ```
  
  
  ---
  
  