Using JS-variable in Yesod handler's code

90 views Asked by At

I know that we can use Haskell data in the Julius-code, for example:

$(function(){
    $("section.#{sectionClass}").hide();
});

But how can I use JS-variable in the Haskell code? For example:

... in some .julius
$(function set_global_variable( value ) {
    window.myGlobalValue = value;
});

... in some handler, pseudocode:
getMyPageR :: Handler Html
getMyPageR = do
    let globalValue = [julius|window.myGlobalValue;|]
    ...

Is it possible?

1

There are 1 answers

0
Michael Snoyman On BEST ANSWER

No, there's no way to do that. The yesod code runs server side, and the JavaScript client side. The only way to achieve that kind if thing is to have the JavaScript send values back to the server.