Answer the question
In order to leave comments, you need to log in
Can I change the Bitrix component template on the fly?
Friends, I just recently started working with Bitrix, just recently. Very interesting, I like it, no matter what))
But now the task arose, to add the ability to display goods with tiles (now a list).
The output template is not standard and it does not have a tile output. As I understand it, you need to write your own template with tiles.
But... after looking at the current catalog template code, I went crazy.... there are 885 lines of good thoughtful :) php code and doing the same would not be a real task for me now.
But when you turn on the standard template for the catalog component, you get a tile that is what you need, if you finish it a little, it will generally be a gun.
Is it possible to make a button to change the template for a component and display it for the user (as it usually happens in any IM - an icon with a list, an icon with a tile)? How to do it ?
Answer the question
In order to leave comments, you need to log in
Yes it is possible.
1. Make a link switch tile, list.
2. In the link, enter the parameter ?listType=list and ?listType=card
3. On the page with the call of the component or inside the complex component, write the processing of the passed parameter
4. If it matches, assign the value to the variable with the template name
5. If it does not match, then the default value
6. Write the received value to the session or cookie
7. Check the value in the cookie or session before connecting the template
8. Insert a variable with the template name.
If you need to do it on Ajax, then everything is the same, just replace the link with an Ajax request to the same page and add it before the component
AND after the component
Naturally with a check for the presence of the passed parameter.
Further, as a result of ajax, simply paste the html into the list box
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question