0

Ok, here is the problem:

I have a search that gets results from server through ajax and I need to be able to include a view file with variable for each result.

Each result block would be included normally like this:

{include file={#modules_box#} foo="bar"}

How can I parse a codeigniter template file in javascript to pass correct 'foo' and show the results properly? I can go through each object in included template and replace those with search results but it is lengthy ('foo' is an object) and it creates lengthy task if modules_box view is updated later on.

Or am I looking from very wrong point of view? Should it be done differently?

5
  • You are getting the results in json format and need to format them in a view to pass them to the browser? Or it's the other way around.. You want to pass results in json to your javascript? Commented Jan 23, 2012 at 18:09
  • @chaft I am getting the results in json and I want to format them in a view Commented Jan 23, 2012 at 18:34
  • Then you need to either do some fancy string manipulation in js, or you need to rewrite the view in a js-friendly template. Commented Jan 23, 2012 at 19:26
  • @swatkins Don't wanna do lengthy string manipulation in js. Could you point to an example for writing a js-friendly template? Commented Jan 23, 2012 at 20:26
  • 1
    handlebarsjs.com - github.com/janl/mustache.js - documentcloud.github.com/underscore/#template Commented Jan 23, 2012 at 20:37

1 Answer 1

1

Alright, I have solved it using:

Smarty Parser for Javascript and php.js

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.