Answers.Body: <p>To have asset selection and upload in your twig, you can use <a href="https://github.com/craftcms/cms/blob/develop/src/templates/_includes/forms/elementSelect.html" rel="nofollow noreferrer">elementSelectField</a></p>
  <p>the code i wrote here is just sample and definitely you need to review, consider security and validation</p>
  <p>firstly you should have an extra public attribute to keep selected asset on settings model:</p>
  <pre><code>class Settings extends Model
  {
      .....
      public $imageId = [];
      .....
  </code></pre>
  <p>in your settings.twig template you use elementSelectField like:</p>
  <pre><code>{{ forms.elementSelectField({
      label: &quot;image&quot;,
      id: &quot;imageId&quot;,
      name: &quot;imageId&quot;,
      viewMode: &quot;list&quot;,
      elementType: 'craft\\elements\\Asset', //limit to to asset element type
      selectionLabel: &quot;Add Images&quot;,
      sources: ['folder:'~folderUid], //if you want to limit it to one volume folder not all volumes
      required: false,
      errors: settings.getErrors('imageId'),
      limit: 2, // if you want maximum two images 
      elements: images,  // at first it is null, then we pass selected assets as images 
      criteria: { kind: 'image'} // because you want only images
  }) }}
  </code></pre>
  <p>in settingsHtml() method:</p>
  <pre><code>use craft\records\VolumeFolder;
  protected function settingsHtml()
  {
      $settings = $this-&gt;getSettings();
      // to load currently selected assets 
      $images = [];
      if ($settings-&gt;imageId) {
          foreach ($settings-&gt;imageId as $imgId) {
              $images[] = Craft::$app-&gt;elements-&gt;getElementById($imgId);
          }
      }
      //to limit asset selection to one folder
      $volume = Craft::$app-&gt;volumes-&gt;getVolumeByHandle('volumeHandle');//it could be the volume handle you created before
      $volFolderRecord = VolumeFolder::findOne([
          'volumeId' =&gt; $volume-&gt;id
      ]);
      $folderUid = $volFolderRecord-&gt;uid;
      return \Craft::$app-&gt;getView()-&gt;renderTemplate(
          'plugin-handle/settings',[ 
              'settings' =&gt; $settings,
              'images' =&gt; $images
              'folderUid' =&gt; $folderUid
       ]);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-11T13:22:17.430Z
Answers.Text: @DTS as i said in my answer this is only a sample. but have you copied exact code without any change? and which line of code has error?
Answers.UserDisplayName: user9975
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-12T17:41:36.107Z
Answers.Text: @dts something is wrong with $setting. maybe you overwritted it. try to do craft::dd($settings) after $this->getSettings(); and also before $settings->imageId and see what it returns.
Answers.UserDisplayName: user9975
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-14T07:07:01.743Z
Answers.Text: Thank you for the response. Happy to hear from you. I will definitely Look into it.
Answers.UserDisplayName: DTS
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-01T11:45:16.803Z
Answers.Text: How to save the selected assets values in this??
Answers.UserDisplayName: DTS
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-01T12:27:47.907Z
Answers.Text: @DTS in this case, no need to do anything. Craft does it. you can get image ids in your controller from plugin setting with $imageids = \yournamespace\Plugin::getInstance()->getSettings()->imageId;
Answers.UserDisplayName: user9975
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-24T12:26:23.217Z
Answers.LastActivityDate: 2021-12-27T15:00:35.773Z
Answers.LastEditDate: 2021-12-27T15:00:35.773Z
Answers.UserDisplayName: user9975
Body: <p>I am creating a plugin that is based on images the admin will upload some sort of images in plugin settings not sure how to creat image field setting in plugin</p>
  
Tags: <craft3><plugin-development><templating><assets>
Title: Want to use assets field my template settings in custom plugin craftcms
ThreadText: # Want to use assets field my template settings in custom plugin craftcms
  
  (Asked by: username_0 on 2021-12-21)
  
  I am creating a plugin that is based on images the admin will upload some sort of images in plugin settings not sure how to creat image field setting in plugin
  
  **Tags:** craft3, plugin-development, templating, assets
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-12-24. Score: 2
  
  To have asset selection and upload in your twig, you can use [elementSelectField](https://github.com/craftcms/cms/blob/develop/src/templates/_includes/forms/elementSelect.html)
  
  the code i wrote here is just sample and definitely you need to review, consider security and validation
  
  firstly you should have an extra public attribute to keep selected asset on settings model:
  
  ```
  class Settings extends Model
  {
      .....
      public $imageId = [];
      .....
  
  ```
  
  in your settings.twig template you use elementSelectField like:
  
  ```
  {{ forms.elementSelectField({
      label: "image",
      id: "imageId",
      name: "imageId",
      viewMode: "list",
      elementType: 'craft\\elements\\Asset', //limit to to asset element type
      selectionLabel: "Add Images",
      sources: ['folder:'~folderUid], //if you want to limit it to one volume folder not all volumes
      required: false,
      errors: settings.getErrors('imageId'),
      limit: 2, // if you want maximum two images 
      elements: images,  // at first it is null, then we pass selected assets as images 
      criteria: { kind: 'image'} // because you want only images
  }) }}
  
  ```
  
  in settingsHtml() method:
  
  ```
  use craft\records\VolumeFolder;
  protected function settingsHtml()
  {
      $settings = $this->getSettings();
      // to load currently selected assets 
      $images = [];
      if ($settings->imageId) {
          foreach ($settings->imageId as $imgId) {
              $images[] = Craft::$app->elements->getElementById($imgId);
          }
      }
      //to limit asset selection to one folder
      $volume = Craft::$app->volumes->getVolumeByHandle('volumeHandle');//it could be the volume handle you created before
      $volFolderRecord = VolumeFolder::findOne([
          'volumeId' => $volume->id
      ]);
      $folderUid = $volFolderRecord->uid;
      return \Craft::$app->getView()->renderTemplate(
          'plugin-handle/settings',[ 
              'settings' => $settings,
              'images' => $images
              'folderUid' => $folderUid
       ]);
  
  ```
  
  > **Comments:**
  > **username_1**: @username_0 as i said in my answer this is only a sample. but have you copied exact code without any change? and which line of code has error?  
  > **username_1**: @dts something is wrong with $setting. maybe you overwritted it. try to do craft::dd($settings) after $this->getSettings(); and also before $settings->imageId and see what it returns.  
  > **username_0**: Thank you for the response. Happy to hear from you. I will definitely Look into it.  
  > **username_0**: How to save the selected assets values in this??  
  > **username_1**: @username_0 in this case, no need to do anything. Craft does it. you can get image ids in your controller from plugin setting with $imageids = \yournamespace\Plugin::getInstance()->getSettings()->imageId;  
  
  ---
  
  