Google Maps API Loading in Admin View #998
Unanswered
GiuseppeBosco
asked this question in
Extention Issues
Replies: 1 comment 1 reply
-
Hi Giuseppe, if you want you can contact us, I'll try to help you. Let me know if you still have my contact information. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Okay, I'll translate everything into clear, effective English for your JCB forum post.
Request for Help on JCB Forum: Google Maps API Loading in Admin View
Hello everyone,
I'm encountering an issue loading the Google Maps JavaScript API correctly within one of my Admin Views created with JCB (Joomla Component Builder).
My initial goal is simply to successfully load the API script and see it present in the page's HTML source, using my maps_api_key configured in the component. For now, I'm not concerned with map initialization, just the correct script loading.
I have a field in JCB for the API key (maps_api_key), and I'm trying to use the following PHP code to include the script:
`$app = \Joomla\CMS\Factory::getApplication();
$params = \Joomla\CMS\Component\ComponentHelper::getParams('com_pdvmanager');
$googleMapsApiKey = $params->get('maps_api_key', '');
if (empty($googleMapsApiKey)) {
echo '
} else {
if (!isset($GLOBALS['Maps_loaded'])) {
echo '<script src="https://maps.googleapis.com/maps/api/js?key=' . $googleMapsApiKey . '&libraries=places" async defer></script>';
$GLOBALS['Maps_loaded'] = true;
}
}`
I've attempted to insert this PHP code block (without the outer tags, as JCB handles them automatically) into several PHP fields within my Admin View.
Initially, when using HTMLHelper::_('script', ...), I encountered PHP syntax errors (Unclosed '{') which seemed related to how JCB was processing curly braces. After switching to direct output with echo, the syntax error disappeared, but I cannot find the Google Maps <script> tag in the generated page's HTML source.
I've tried placing it in the following JCB fields, without success in seeing the script loaded:
Target Admin View Default Template Header
Class Header (admin.view.html)
Power Header (admin.view.html)
Target Admin View Model Header
Does anyone have experience with loading external scripts in JCB, especially the Google Maps API, within an Admin View? What is the correct field or strategy to ensure the <script> tag is actually inserted into the generated HTML?
Thank you in advance for your help!
Beta Was this translation helpful? Give feedback.
All reactions