I have been learning a lot about Mura the last couple of weeks while building my first Mura plugin, but I have also had a lot of frustration because some things work differently when you are developing for a front-end page vs. a back-end (admin) page.
In the Mura Developer Documentation it states:
The Event scope simply wraps the current request's event object which contains merged data from both the CFML FORM and URL scopes.
If then goes on to say that the following code should return values from those scopes.
<cfset $.event('property') />
So if I have a URL variable like ?test=123, then this code should return the value '123':
<cfset $.event('test') />
This seems to work fine on pages I create for Mura display objects for the front end of the website, but for pages in the admin area of the site, this method only produces [empty string].
At first I decided that I would just then use FORM and URL normally (i.e FORM.test, URL.test), but then I had to go back to using
I searched and searched and search and I could not find ANY explanation about how this should work or how to make it work like I thought it should. Finally, someone at Blue River told me, on Twitter, that I should init() the MuraScope with the scope that I wanted in the config.cfm file. So I looked into this and it seems that I can do something like this to get part of the behavior I wanted:
<cfset form.siteID = session.siteID />
<cfset $ = application.serviceFactory.getBean('muraScope').init(FORM) />
You always need to pass in the siteID when you init the MuraScope, so I simply added it to the FORM struct and passed in the whole FORM. This seemed to get me PART of what I needed, but I wanted the URL struct in there too. I tried calling init() multiple times, but, as expected, that did not work. Finally, I found this post from Adam Presley on how to merge two structs.
Finally, I ended up doing this in my config.cfm for the plugin.
<cfif not isDefined("$")>
<cfset initArgs = StructNew() />
<cfset StructAppend(initArgs, URL) />
<cfset StructAppend(initArgs, FORM) />
<cfset initArgs.siteID = session.siteID />
<cfset $ = application.serviceFactory.getBean('muraScope').init(initArgs) />
Keep in mind with this code that if the URL and FORM scopes each have a variable with the same name that the FORM scope's value will overwrite the URL's. This is what I wanted, because it is how the other frameworks I use work.
Now, I have NO IDEA, if this is the right way to do this. Like I said, I could not find any other way. If someone knows a better way or if they want to share with me why I should not do this, I would love to hear either way. But now I can use $.event('propertyName') on my admin pages without issue (so far).