Jump to content

[SOLVED] How to add/remove displayed tpl conditionally?


Recommended Posts

Hello,

I have two buttons and I monitor their `onclick` state by using:

<script type="text/javascript">
$(document).ready(function() {
 $('#button1').bind('click', function(){
  });
 $('#button2').bind('click', function(){
  });
});
</script>

How can I remove the currently showing tpl from the page and add a different tpl instead of it?

 

Thanks

Edited by kingsinnersoul (see edit history)
Link to comment
Share on other sites

Good point, I will add the solution in this thread.

Using PS 1.5.4.1 - defauly theme.

 

I took the product-list.tpl file, and wrapped the contents with a `<div>` tag with `id="my_list_div"` - without including the smarty `{if isset($products)}` code at the start and `{/if}` at the end.

 

Then I copied the content within the `<div>` and pasted it within a new `<div>` I created before the `{/if}` at the end. I id'ed this `<div>` with `my_grid_div` id. Modified the new `my_grid_div` contents to look as a nice grid view (css, reorganize contents).

 

Finally, add the following javescript to show or hide `my_list_div` or `my_grid_div`.

<script type='text/javascript'>
$(document).ready(function() {
$('div#my_list_div').hide();
$('div#my_grid_div').show();
$("#grid_button_id").addClass("active");
$("#list_button_id").removeClass("active");
});
</script>
Edited by kingsinnersoul (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...