Reputation: 1
I created a plugin that adds a user section and dashboard (.ascx file
) with textfield and button.
Installing and uninstalling the plugin works fine.
But I need a script to be added to each View in the project when the button is pressed.
Upvotes: 0
Views: 89
Reputation: 1985
I'd be interested in knowing what you're trying to do here - I don't really see why you would want to add something to every view file in the site.
However to answer your question. You need to create a backoffice controller. This controller should have an action that enumerates the ~/views/
folder on disk and simply adds your script into every file where you need it to be added. Then you hook your button up to do an ajax request to this controller action and you should be good to go.
Note: you really need to be sure it is a backoffice controller, so it enforces authentication and cannot be called by any unauthenticated request. You don't want to risk having someone just hitting this controller from the outside - only known backoffice users, authenticated in the backoffice should be allowed.
Also note that you should verify that whenever you are going to add this script to your view files - it needs to ensure that it hasn't already been added to the files. Otherwise you will have your script added multiple times if someone clicks the button twice.
There's documentation here on how to add auto routed controllers with backoffice authentication: https://our.umbraco.com/documentation/reference/routing/webapi/
Upvotes: 1