I want to use jquery at server side with node.js mvc framework CompundJS. I want to use jquery ($) in compundjs view. Can someone please tell me how to set up jquery in compundjs for that?
I have installed jQuery using "npm install". I want to use jQuery in compoundjs view to select and change some html tags at server side (depending on the data received from controller action). But I don't know how to configure compundjs for that.
You don't need jQuery on the server. Use the templating languages (that comes with compoundjs by default) instead, they allow you to change html dynamically depending on data that you make available in the controller.
example (using ejs templates)
in app/controllers/somemodel_controller.js:
action('index', function(){
this.title = "theTitle";
this.dataToUseInView = "someData";
this.mySpecialClass = "theClass";
render();
});
in app/views/somemodel/index.ejs:
<h1><%= title %></h1>
<p class="<%= mySpecialClass%>"><%= dataToUseInView %></p>
will render:
<h1>theTitle</h1>
<p class="theClass">someData</p>
view the documentation for the templating language you use.
I don't use CompoundJS, but usually on these frameworks you compile a template. A template has inputs - you should use them as a way to dynamically effect the html. For example, Jade template would allow you to 'inject' the page title:
html(lang="en")
head
title= pageTitle
then you should have some kind of a render function that you can provide with
{pageTitle:"your title"}
You can use JQUERY just like you use it in a HTML page. Compound do not have any role to play in this.
Just add link to your jquery file and in .ejs and use it as required.