Announcement

#1 2016-10-26 20:11:43

TheDoc
Member
Munich / Germany
2015-10-18
160

Avoid double <script src"xxx"></script> entries?

Hi all,

I have changed my piwigo theme to show the openstreet map from the category page on the picture pages as well. That works great except when showing the gpx file as picture (see http://www.feuster.com/piwigo/picture?/ … ace_center).

Root cause is that I include both osm-gpx.tpl and osm-map.tpl on the same page and so

<script src="/piwigo/plugins/piwigo-openstreetmap/leaflet/leaflet.js"></script>

gets added twice into the <head> section.

Is there any way to avoid that e.g. using some clever smarty feature? So far I haven't been able to come up with something helpful...

Thanks in advance,
Thomas

Offline

 

#2 2016-10-26 22:13:47

TheDoc
Member
Munich / Germany
2015-10-18
160

Re: Avoid double <script src"xxx"></script> entries?

Reply to self and for documentation :-)

In an event handler for 'loc_end_picture' I now call the following:

function cleanup_html_head()
{
    global $template;

    // the variable in $template we're looking for is "html_head_elements"
    // and its an array with one entry for each *.tpl that had a {html_head} section
    if ( count($template->html_head_elements) )
    {
        // combine array elements into one AND split @ newline AND create a unique array
        $template->html_head_elements = array_unique( explode( "\n", implode( "\n", $template->html_head_elements ) ) );
    }
}

Seems to work fine :-)

Offline

 

#3 2016-10-27 14:20:06

flop25
Piwigo Team
2006-07-06
7037

Re: Avoid double <script src"xxx"></script> entries?

Hello
Thx for sharing We have a github repo ; I notify rvelices


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#4 2016-10-27 19:03:35

rvelices
Piwigo Team
2005-12-29
1960

Re: Avoid double <script src"xxx"></script> entries?

Apparently this plug-in does not use the combine script feature that allows any number of plug-ins to load a script exactly once.

The html head was not intended to load external scripts or css

Offline

 

#5 2016-10-27 19:46:42

TheDoc
Member
Munich / Germany
2015-10-18
160

Re: Avoid double <script src"xxx"></script> entries?

Well, tell that to the developer of the piwigo-openstreetmap plugin :-)

As for including my fix in the general code: Thought about it as well BUT

- doesn't seem to be a common problem
- might have a performance hit since its done for all and an pages

I'd rather add it to the page where all the helpful code snippets are collected...

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2022 · Contact