Answers.Body: <p>Based on the discussion you'll need to implement a <code>fetch</code> function similar like Craft does it with the <code>ElementCriteriaModel</code> / <code>ElementQuery</code>. So you'll return some kind of search object until you execute the <code>.find()</code>/<code>fetch()</code> (or whatever you like to call it) function</p>
  
  <pre><code>class ClassName{
  
      /** @var array $_searchObjects */
      private $_searchObjects;
  
      /**
       * @param $something
       *
       * @return $this
       */
      public function exampleFunction($something){
          $this-&gt;_searchObjects = ['test', 'insert', 'your', 'array', 'here'];
  
          return $this;
      }
  
      /**
       * @param $string
       *
       * @return $this
       */
      public function hide($string){
          // filter your elements
          $this-&gt;_searchObjects = ...//
  
          return $this;
      }
  
      /**
       * @return array
       */
      public function find(){
          return $this-&gt;_searchObjects;
      }
  }
  </code></pre>
  
  <p>You can then use it like</p>
  
  <pre><code>{% set elements = craft.plugin.exampleFunction.find() %}
  {% set filterElements = craft.plugin.exampleFunction.hide('something').find() %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-17T07:29:01.323Z
Answers.Text: Thank you so much, it seems to be working for me. Thanks again !!.
Answers.UserDisplayName: Pravesh Tiwari
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-17T07:22:24.403Z
Answers.LastActivityDate: 2018-04-17T07:22:24.403Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I am new to craft and I need help to understand how plugins work.
  I am trying inject these functions to the <code>CraftVariable</code> </p>
  
  <pre><code>{% for item in craft.plugin.exampleFunction(test).hide("noTitle") %}  
  </code></pre>
  
  <p><code>craft.plugin.exampleFunction(test)</code> is working perfectly 
  but <code>.hide()</code> is not. Can anybody tell me how to call this function?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-17T07:07:56.177Z
Comments.Text: Could you tell us what you want to achieve? What does your `exampleFunction` return?  It should be an object with the function `hide` in it
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-17T07:12:00.277Z
Comments.Text: Do you have any sample for similer?
Comments.UserDisplayName: Pravesh Tiwari
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-17T07:13:27.163Z
Comments.Text: Since I don't know you want to do I can't really provide any help. I can create a simple example but that won't help you
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-17T07:15:02.167Z
Comments.Text: I just need to know how to access hide function as my exampleFunction is returning array. What changes i need to make here?
Comments.UserDisplayName: Pravesh Tiwari
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-17T07:15:39.453Z
Comments.Text: What should your hide function be? what should it do?
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-17T07:17:03.567Z
Comments.Text: okay Let me explain the scanerio: my example function is returning a custom array. and I want to filter records(array) if any custom fields value is blank
Comments.UserDisplayName: Pravesh Tiwari
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-17T07:17:46.370Z
Comments.Text: also put sorting on records similer to craft.plugin.exampleFunction(test).hide("noTitle").sort('price', ASC)
Comments.UserDisplayName: Pravesh Tiwari
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-17T07:20:18.837Z
Comments.Text: $query = \craft\elements\Entry::find();
  $query->section('products'); 
  $tariffSections = $query->all();
Comments.UserDisplayName: Pravesh Tiwari
Tags: <plugin-development><craft3>
Title: Plugin development Craft CMS 3
ThreadText: # Plugin development Craft CMS 3
  
  (Asked by: username_0 on 2018-04-17)
  
  I am new to craft and I need help to understand how plugins work.
  I am trying inject these functions to the `CraftVariable`
  
  ```
  {% for item in craft.plugin.exampleFunction(test).hide("noTitle") %}  
  
  ```
  
  `craft.plugin.exampleFunction(test)` is working perfectly
  but `.hide()` is not. Can anybody tell me how to call this function?
  
  **Tags:** plugin-development, craft3
  
  > **Comments:**
  > **username_1**: Could you tell us what you want to achieve? What does your `exampleFunction` return?  It should be an object with the function `hide` in it  
  > **username_0**: Do you have any sample for similer?  
  > **username_1**: Since I don't know you want to do I can't really provide any help. I can create a simple example but that won't help you  
  > **username_0**: I just need to know how to access hide function as my exampleFunction is returning array. What changes i need to make here?  
  > **username_1**: What should your hide function be? what should it do?  
  > **username_0**: okay Let me explain the scanerio: my example function is returning a custom array. and I want to filter records(array) if any custom fields value is blank  
  > **username_0**: also put sorting on records similer to craft.plugin.exampleFunction(test).hide("noTitle").sort('price', ASC)  
  > **username_0**: $query = \craft\elements\Entry::find(); $query->section('products');  $tariffSections = $query->all();  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-04-17. Score: 3 | Accepted answer
  
  Based on the discussion you'll need to implement a `fetch` function similar like Craft does it with the `ElementCriteriaModel` / `ElementQuery`. So you'll return some kind of search object until you execute the `.find()`/`fetch()` (or whatever you like to call it) function
  
  ```
  class ClassName{
  
      /** @var array $_searchObjects */
      private $_searchObjects;
  
      /**
       * @param $something
       *
       * @return $this
       */
      public function exampleFunction($something){
          $this->_searchObjects = ['test', 'insert', 'your', 'array', 'here'];
  
          return $this;
      }
  
      /**
       * @param $string
       *
       * @return $this
       */
      public function hide($string){
          // filter your elements
          $this->_searchObjects = ...//
  
          return $this;
      }
  
      /**
       * @return array
       */
      public function find(){
          return $this->_searchObjects;
      }
  }
  
  ```
  
  You can then use it like
  
  ```
  {% set elements = craft.plugin.exampleFunction.find() %}
  {% set filterElements = craft.plugin.exampleFunction.hide('something').find() %}
  
  ```
  
  > **Comments:**
  > **username_0**: Thank you so much, it seems to be working for me. Thanks again !!.  
  
  ---
  
  