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 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?

1 Answer 1


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 plugin, which was created specifically to allow you to add JavaScript in the control panel.

  • I don't think this will work in my case, since I need access to $this->url
    – Bryce
    Feb 2, 2021 at 17:06
  • 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 github.com/craftcms/cms/blob/develop/src/elements/…
    – Ben Croker
    Feb 2, 2021 at 22:30
  • Whoops, yep, updated my question with a link
    – Bryce
    Feb 2, 2021 at 22:37
  • 1
    After a quick scan of the code, I don't see any way of achieving what you want, even with a module/plugin.
    – Ben Croker
    Feb 3, 2021 at 7:52
  • Alright, thanks for looking into it. I'll just stick with my hacked version and disable updates for now
    – Bryce
    Feb 3, 2021 at 23:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.