Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
How to pass xml variables to JS via php

So, I'm trying to connect my xml input to Javascript file through php(optional). I have to concatenate the xml input with all the h1 tags of my site. I'm trying to avoid inline javascript.

This is my php snippet for loading the js file.

$this->app->getDocument()->getWebAssetManager()->registerAndUseScript('plg_system_headings', 'media/plg_system_headings/js/index.js', [], ['defer' => true]);

And this is my xml snippet:

<files>
        <filename plugin="headings">headings.php</filename>
    </files>
    <media folder="media" destination="plg_system_headings">
        <!--<folder>css</folder>-->
        <folder>js</folder> 
    </media>
    <languages>
        <language tag="en-GB">language/en-GB.plg_system_headings.ini</language>
    </languages>
    <config>
        <fields name="params">
          
            <fieldset name="basic">
                <field
                    name="text_input"
                    type="text"
                    label="HEADINGS_TEXT_VS"
                    default="Greetings!!"
                />
            </fieldset>
          
        </fields>
    </config>

now I want the variable $this->params->get('text_input') to get passed in the js file. I tried writing it this way but it's not able to access this variable.

 window.onload = () => {
    // Display the alert
    let h1 = document.getElementsByTagName('h1')[0];
    h1.innerHTML= h1.concat(" . $this->params->get('text_input') . ");
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda