Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Weird load of google maps in modular page

Started by Francesco 9 years ago · 7 replies · 857 views
9 years ago

Hello everyone!
I have a weird problem with google maps in a modular page and I hope someone may have a guess on what is causing this.

I have a modular page with a module for showing googlemaps. Since this is the only page with a map I loaded the script only in this module template with:
{% do assets.addJs('https://maps.googleapis.com/maps/api/js?key=', {'priority':'90','loading': 'defer'}) %}

Here the problem. On localhost everything is fine, but online the script is not loaded and it doesn't appear at the bottom. Any ideas?

9 years ago

You are including the javascript within the modular page itself?
Where in the modular page is the javascript being called? It is outside of the content block you are likely using to render the page?

9 years ago

You're probably missing the maps API key. Check your browser's console. You should find a javascript error...

9 years ago

@seb3000 I've the API key, but I haven't posted here ;)

@Sockfuzz Actually I didn't add the javascript to the modular.html.twig, I added it to the module template map.html.twig that is one of modules in "contacts page".
Like this:

<details>
<summary>page folder structure</summary>

06.contacts
_module01
_module02
_map < this is the module where I want to put the map javascript

</details>

The structure of my map.html.twig is the following:

<details>
<summary>map.html.twig</summary>

{% do assets.addJs('https://maps.googleapis.com/maps/api/js?key=', {'priority':'90','loading': 'defer'}) %}

HTML
        <div class="contact-us-area padding-top">
            <div id="googleMap" style="width:100%;height:485px;"></div>
        </div>'

</details>

In localhost the script is loaded at the bottom, online it's not being loaded at all

9 years ago

Disable TWIG Caching for the modular page.

9 years ago

Sorry for the delay guys.
@paul actually that solution can not work since it's not possible to add a block to a module template (it can't have the extends twig tag)
@chris_jung well I didn't thought about that and it was a possible solution, unfortunatelly it didn't worked aah.

Well I made a lot of tests and nothing worked, I'm just going to leave the script in base template for now. If I can find a solution I'll let you know.

Thanks anyway! :)

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 82 12 hours ago
General · by pamtbaau, 17 hours ago
1 55 16 hours ago
General · by Andy Miller, 1 day ago
0 45 1 day ago
General · by Marcel, 12 months ago
6 348 5 days ago
General · by Duc , 5 days ago
3 43 5 days ago