Hi all
1. I need to include a own javascript, which i want to include in multiple modules (index_products, index_nested) so i don't have to maintain same code twice.
In which folder should i save this javascript, so it's correct as it should? ext?
2. I made a class for extending the splitPageResults, where do i have to put my extension so it's autoloaded?
thank you!
Design / folder of Javascript question
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: Design / folder of Javascript question
Yes, ext is probably the best place.
In catalog, includes/system/override
Note that it won't actually be autoloaded until it is invoked by name.
-
loop
- Contributor
- Posts: 253
- Joined: Thu Mar 25, 2021 12:26 pm
- Phoenix Version:
- Has thanked: 7 times
- Been thanked: 3 times
Re: Design / folder of Javascript question
hi ecartz
the class file is now in includes/system/override
whenn i try now in product_listing.php to initiate i get a error:
if i have there the " include("includes/system/ovverride/splitPageResultsInfinite.php");" it works....
and a other Pattern question: i made a productfilter module in index_products, which i need also in index_nested, what is the most elegant way to reuse the code? one idea is to add the javascript code in a external file and include it in the header, so the javasript is not duplicated. But most other code would be doubled...which is ugly to maintain...
the class file is now in includes/system/override
whenn i try now in product_listing.php to initiate i get a error:
Code: Select all
$listing_split = new splitPageResultsInfiniteScrolling($listing_sql, $num_list, 'p.products_id');
Fatal error: Uncaught Error: Class 'splitPageResultsInfiniteScrolling' not found in /mnt/lamp-www-data/beta_shop/templates/default/includes/components/product_listing_infinite.php:13 Stack trace: #0
..
...
and a other Pattern question: i made a productfilter module in index_products, which i need also in index_nested, what is the most elegant way to reuse the code? one idea is to add the javascript code in a external file and include it in the header, so the javasript is not duplicated. But most other code would be doubled...which is ugly to maintain...
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: Design / folder of Javascript question
Name the file split_page_results_infinite_scrolling.php
When I first made the autoloader, we had both snake_case and camelCase class names but only snake_case file names (plus a few exceptions that didn't fit either pattern). So it autoloads camelCase classes from snake_case file names.
Someday, I may go through and rename all the camelCase classes to be snake_case. That would allow me to drop the camelCase to snake_case converter. But since it works (albeit with occasionally confusing behavior), it hasn't been a big priority.
Also, if you have Scrolling in the class name, it needs to be in the file name too.
When I first made the autoloader, we had both snake_case and camelCase class names but only snake_case file names (plus a few exceptions that didn't fit either pattern). So it autoloads camelCase classes from snake_case file names.
Someday, I may go through and rename all the camelCase classes to be snake_case. That would allow me to drop the camelCase to snake_case converter. But since it works (albeit with occasionally confusing behavior), it hasn't been a big priority.
Also, if you have Scrolling in the class name, it needs to be in the file name too.