WBCE / WBCE_CMS

Core package of WBCE CMS. This package includes the core and the default addons. Visit https://wbce.org (DE) or https://wbce-cms.org (EN) to learn more or to join the WBCE CMS community.
https://wbce-cms.org
GNU General Public License v2.0
31 stars 22 forks source link

Wrong order of included JS/jQuery in head of template #472

Closed instantflorian closed 4 years ago

instantflorian commented 4 years ago

If the output of a template is buffered with ... ob_start(); page_content($k); $contentblock[$k] = ob_get_clean(); ... and in the template that code is placed before the register_frontend_modfiles() calls, in the generated frontend page the links to the frontend.js files are placed before the jquery files, which leads to JS errors and non-working modules which depend on jQuery. E.g. instead of `

<script src="https://example.com/include/jquery/jquery-insert.js"></script>
<script src="https://example.com/include/jquery/jquery-migrate-min.js"></script>
<script src="https://example.com/include/jquery/jquery_theme.js"></script>
<script src="https://example.com/modules/cookieconsent/frontend.js"></script>
<script src="https://example.com/modules/accordion/frontend.js"></script>
<script src="https://example.com/modules/miniform/frontend.js"></script>
<script src="https://example.com/modules/minigal2/frontend.js"></script>

`

the code is generated like `

<script src="https://example.com/modules/minigal2/frontend.js"></script>
<script src="https://example.com/include/jquery/jquery-min.js"></script>
<script src="https://example.com/include/jquery/jquery-insert.js"></script>
<script src="https://example.com/include/jquery/jquery-migrate-min.js"></script>
<script src="https://example.com/include/jquery/jquery_theme.js"></script>
<script src="https://example.com/modules/cookieconsent/frontend.js"></script>`

Strange: cookie consent's frontend.js seems not to be affected (o_O)

instantflorian commented 4 years ago

Solution: require_once __DIR__.'/info.php'; foreach($block as $k=>$v){ if ($k == 99) {continue;} ob_start(); page_content($k); $contentblock[$k] = ob_get_clean(); } or similiar content fetching code has to be placed AFTER register_frontend_modfiles('css'); register_frontend_modfiles('jquery'); register_frontend_modfiles('js');