Answers.Body: <p>The only feasible way of doing this without it being overwritten in each Craft update is by manipulating the elements using JavaScript. You can of course do this using your own module or plugin, but an easier approach would be to use the <a href="https://plugins.craftcms.com/cp-js" rel="nofollow noreferrer">Control Panel JS</a> plugin, which was created specifically to allow you to add JavaScript in the control panel.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-02T17:06:41.647Z
Answers.Text: I don't think this will work in my case, since I need access to `$this->url`
Answers.UserDisplayName: Bryce
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-02T22:30:34.017Z
Answers.Text: Can you provide a link to the exact line you are changing? Line 1650 is pointing to something else in the current develop branch at https://github.com/craftcms/cms/blob/develop/src/elements/Asset.php#L1650
Answers.UserDisplayName: Ben Croker
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-02T22:37:54.720Z
Answers.Text: Whoops, yep, updated my question with a link
Answers.UserDisplayName: Bryce
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-03T07:52:02.347Z
Answers.Text: After a quick scan of the code, I don't see any way of achieving what you want, even with a module/plugin.
Answers.UserDisplayName: Ben Croker
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-03T23:25:06.217Z
Answers.Text: Alright, thanks for looking into it. I'll just stick with my hacked version and disable updates for now
Answers.UserDisplayName: Bryce
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-29T08:48:04.100Z
Answers.LastActivityDate: 2021-01-29T08:48:04.100Z
Answers.UserDisplayName: Ben Croker
Body: <p>I'm making a change to the CP so that clicking an asset thumbnail from the asset preview HUD will open the asset in a new tab. Specifically, I'm changing <a href="https://github.com/craftcms/cms/blob/develop/src/elements/Asset.php#L1685" rel="nofollow noreferrer">line 1685</a> of <code>craftcms/cms/src/elements/Asset.php</code> to this:</p>
  <p><code>&lt;/div&gt;&lt;a href=&quot;' . $this-&gt;url . '&quot; target=&quot;_blank&quot; style=&quot;width:100%;height:100%;position:absolute;&quot;&gt;&lt;/a&gt;';</code></p>
  <p>This achieves what I want, but it's obviously not the right way to do it. My question is, what is the right way? Can I do this with a module as opposed to a full plugin?</p>
  
Tags: <plugin-development><control-panel>
Title: How to properly change / add to CP HTML
ThreadText: # How to properly change / add to CP HTML
  
  (Asked by: username_0 on 2021-01-18)
  
  I'm making a change to the CP so that clicking an asset thumbnail from the asset preview HUD will open the asset in a new tab. Specifically, I'm changing [line 1685](https://github.com/craftcms/cms/blob/develop/src/elements/Asset.php#L1685) of `craftcms/cms/src/elements/Asset.php` to this:
  
  `</div><a href="' . $this->url . '" target="_blank" style="width:100%;height:100%;position:absolute;"></a>';`
  
  This achieves what I want, but it's obviously not the right way to do it. My question is, what is the right way? Can I do this with a module as opposed to a full plugin?
  
  **Tags:** plugin-development, control-panel
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-01-29. Score: 2
  
  The only feasible way of doing this without it being overwritten in each Craft update is by manipulating the elements using JavaScript. You can of course do this using your own module or plugin, but an easier approach would be to use the [Control Panel JS](https://plugins.craftcms.com/cp-js) plugin, which was created specifically to allow you to add JavaScript in the control panel.
  
  > **Comments:**
  > **username_0**: I don't think this will work in my case, since I need access to `$this->url`  
  > **username_1**: Can you provide a link to the exact line you are changing? Line 1650 is pointing to something else in the current develop branch at https://github.com/craftcms/cms/blob/develop/src/elements/Asset.php#L1650  
  > **username_0**: Whoops, yep, updated my question with a link  
  > **username_1**: After a quick scan of the code, I don't see any way of achieving what you want, even with a module/plugin.  
  > **username_0**: Alright, thanks for looking into it. I'll just stick with my hacked version and disable updates for now  
  
  ---
  
  