Fórumok

Accessing LR variables in web content javascript

thumbnail
Pete Helgren, módosítva 11 év-val korábban

Accessing LR variables in web content javascript

Regular Member Bejegyzések: 225 Csatlakozás dátuma: 2011.04.07. Legújabb bejegyzések
I have seen many different flavors of this but not an exact match with a *working* example (or perhaps I failed to understand something). Here is what I need:

Within a page there are three JavaScript text boxes when you can enter JavaScript (Manage-->Page). What I would like to do is to have a link within web content that invokes JavaScript with then grabs a value from an LR variable that can be used in the JavaScript itself.

So for example. In the web content page href I would have something like:

<a href="javascript:void(0);" onclick="runReportForLoggedInUser()">Run Report</a>

Then in the JavaScript (Manage-->page) I would have something like this:

function runReportForLoggedInUser(){

var user_email = $user_email_address;

runClassReport(user_email);

}

runClassReport is a javscript method available from a javascript library that is included in the portal_normal.vm template in the theme.

Yeah, I could move the variable logic into the javascript in the portal_normal.vm template but that is a hassle in that every time I needed to invoke something requiring LR variables I'd need to modify the javscript and redeploy the theme.

So, specifically: If I want LR variables (from init.vm for example) to be used in the JavaScript blocks in the Manage-->page option. How do I do that? I have seen examples of modifying or creating a web content template but even those examples don't show how to hook up exposed variables in the JavaScript blocks found in Manage-->Page.

Using 6.0.6 of LR....