Javacsript code

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
Gregory45engineer
New Member
New Member
Posts: 2
Joined: Wed Mar 26, 2014 4:17 pm

Javacsript code

Post by Gregory45engineer »

i have simple page mada with cms ms. I am using few additional modules. Products and prerequisites for it.

I need a fast way to show items list from only one category. I want to select category from menu on sidebar. I have simple links there. I want to change category with simple javascript function that will assign correct category for the products to be shown on main page.

On "contents" i have only {Products category='cat'}.

I want to change that variable in script.

But in console from firefox developer tools i got error message that my script isn't found. Where is the bes way to insert my scripts and link them. Or maybe someone have simpler solution to my problem.

O0
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Javacsript code

Post by velden »

I don't know products module, but:

First of all it's hard for me to understand what's going wrong as you didn't provide a link to the website/page.

You can include Javascript in several ways:
- in page template
- in page specific metadata
- even in page content (wouldn't recommend it)
- in Global Content Block that is included in page/page template

For options above:
As Smarty uses the curly brackets {} for its tags make sure you don't break it with your Javascript code; use {literal}{/literal} around your javascript code OR make sure all curly brackets in your JAVASCRIPT are surrounded by a white space.

- as a link to a .js file

That said, note that you can NOT use a javascript (client side) to change a Smarty variable (server side) after the page has been loaded.
That means you have to pass a variable via JS to the webserver via a new page request. YOUR template should read the variable and use that for the call of {Products}. If you don't want page reloads you should use ajax for it.

You can also load ALL categories and it's products in one page and use JS to hide/show the right category (not efficient if you have many categories/products).

Or look for a template to show only a list of categories and use that to provide links to the right category.
Post Reply

Return to “Modules/Add-Ons”