2013-04-13 21 views
8

Sto provando a caricare il file js nel footer del mio magento. Sto usando questo codice ma mi restituisce un errore. Qualsiasi aiuto? Molte grazie!Magento aggiunge Js al footer

code used in local.xml: 

<layout> 
<default> 
    <reference name="footer"> 
     <action method="addJs"><script>js/file.js</script></action> 
    </reference> 
</default> 
</layout> 
+0

"ma mi danno indietro un errore ", quale errore? – plalx

risposta

1

riferimento alla mia risposta qui:
How to add Javascript files in body part (not header) through layout xml files in magento

La cosa migliore è quello di creare un file .phtml con il tuo link js e aggiungerlo al tuo piè di pagina utilizzando questo formato:

<layout> 
    <default> 
     <reference name="footer"> 
      <block type="core/template" name="unique_name_here" template="path/to/js.phtml" /> 
     </reference> 
    </default> 
</layout> 

Per riferimenti come questo, il footer caricherà automaticamente tutti i blocchi html figlio. Parent .phtml file di modello possono avere bisogno di una chiamata getChildHtml in loro per essere mostrato, in questo modo:

<?php echo $this->getChildHtml('unique_name_here'); ?> 

Che dovrebbe farlo.

5

Per Magento v1.6 + (necessario eseguire il test nelle versioni precedenti);

1 - creare un file di modello in page/html/footer/extras.phtml con questo contenuto:

<?php echo $this->getCssJsHtml() ?> 

2 - Aggiungere questo nodo html al layout xml:

<reference name="before_body_end"> 
<block type="page/html_head" name="extra_js" as="extraJs" after="-" template="page/html/footer/extras.phtml"> 
    <action method="addItem"><type>skin_js</type><name>js/jquery.min.js</name></action> 
</block> 

3 - Questo è tutto !

22

Trova page.xml del vostro tema e trovare le seguenti

<block type="core/text_list" name="before_body_end" as="before_body_end" translate="label"> 

e inserire il seguente poco prima:

<block type="page/html_head" name="jsfooter" as="jsfooter" template="page/html/jsfooter.phtml"> 
    <action method="addJs"><script>your_script.js</script></action> 
</block> 

Creare il file di modello in app/design/frontend/[package]/[theme]/template/page/html/jsfooter.phtml e inserire il seguente:

<?php echo $this->getCssJsHtml() ?> 

Aggiungi qui sotto il modello appena prima di chiudere t ag:

<?php echo $this->getChildHtml('jsfooter') ?> 
+0

L'ho provato. Funziona alla grande .. +1 – Shatir

0

È possibile aggiungere nuovo blocco in page.xml

<block type="core/text_list" name="before_body_end" as="before_body_end" translate="label"> 
    <block type="page/html_head" name="footerjscss" as="footerjscss" after="-" template="page/html/footerjscss.phtml"/> 
</block> 

quindi aggiungere JS & file CSS in qualsiasi layout.xml

<reference name="footerjscss"> 
    <action method="addItem"><type>skin_js</type><name>js/slideshow.js</name></action> 
    <action method="addItem"><type>skin_css</type><name>css/madisonisland.css</name><params/><if/></action> 
</reference> 

creare il file .phtml nella pagina/html/footerjscss.phtml e aggiungi successivo

<?php echo $this->getCssJsHtml() ?> 

Ora richiamo del blocco nel modello di pagina “3columns.phtml” e così via si avrà bisogno di uscita di questo blocco prima del tag:

<?php echo $this->getChildHtml('before_body_end') ?> 

consultare il codice qui:http://blog.rahuldadhich.com/magento-load-css-js-footer/

Problemi correlati