1

I'm wondering how to let my customer 'personalize' their view executing some of my custom functions using an mustache/handlebar format, but I'm not able to understand how to do it effectively. I have it in my mind the flow, but in code, I don't know where to start.

Example given: I want my users to be able to invoke a function/method called read_json(url,key)

So in my mind, the flow should be to have a template like mustache or liquid and have: Today the weather is {{read_json(https://weathersystem,temperature)}} degrees and have it rendered to: Today the weather is 56 degrees.

Or maybe having a set of functions that the user will declare as variable weather somewhere in my rails database, specific to the user like: weather=read_json("https:/weathersystem", temperature) and then the user would be able to do something like: Today the weather is {{weather}} degrees

Since the text or function the user might want to add or {{ function }} to be rendered every time it's invoked by the users since the text they have this could be rendered in a normal view or into an API response.

I'm kinda struggling figuring it out what or how can be done.

Cheers!

1 Answer 1

1

I think it should be done on client side

so if you use jQuery, you can do this

your view file: x.html

<div>Today the weather is <span class="read-json" data-type="weathersystem" data-subtype="temperature"></span> degrees</div>

javascript file

$('.read-json').each(function(el) {
   var $el = $(el)
   var type = $el.data('type')
   var subType = $el.data('subType')
   // url = ... set URL based on `type` and `subType` variable above 
   $el.load(url)
}
2
  • Hi Saiqul, thanks for taking the time answering, but sadly, this could not match the need that I have. I want the function in mustache or {{ function }} to be rendered every time it's invoked by the users since the text they have this could be rendered into an api response.
    – Paco V.
    Oct 31, 2018 at 11:46
  • 'read_json' is a javascript function, right? if it's a asynchronous request, then read this one to implement your own helper stackoverflow.com/questions/14666557/…
    – Saiqul Haq
    Nov 1, 2018 at 5:05

Your Answer

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

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