Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

894
Vistas
how can i pass a variable from an EJS page to another EJS page

Hello
how can i pass a variable from an EJS page to another EJS page.
For example, I have this page

    // insertion.ejs //




<!DOCTYPE html>
            <html lang=”en”>
            <head></head>
            <header>
                <% include ../views/header %>
            </header>
            <body>
            <script>
            var a="hello";
            </script>
            </body>
        </html>

And this page

 // get.ejs //



        <!DOCTYPE html>
            <html lang=”en”>
            <head></head>
            <header>
                <% include ../views/header %>
            </header>
            <body>
            <script>
            var b 
            </script>
            </body>
         </html>

So how can I pass the content of the variable a to the variable b

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

If you mean to pass the value when a user clicks a link and goes from one page to the other, then you can use a query parameter and have a link like:

<a href="page2?name=value">link</a>

where name is the name of the query parameter and value is its value, that could be populated by the EJS template with an appropriate data.

Now you could get that parameter in your route handler and pass it to the template with other variables or you could access it by the client-side JavaScript on the page.

If you want to pass the variable in a sense that you want to have that variable available to a user then you need to use some session storage, a cookie or local storage.

If you want to pass the variable from one page to the other all users just to reduce duplication then you should use include to include that in all pages that need it or to pass it by the handlers.

This is not very clear from your question what is your intention but this is more or less what you can do in all scenarios.

about 4 years ago · Santiago Trujillo Denunciar

0

You can use LocalStorage concept. Here is the explanation how to use local storage. https://www.w3schools.com/html/html5_webstorage.asp

about 4 years ago · Santiago Trujillo Denunciar

0

Well you can model binding in one page, but not two separate page. For this purpose you have cook up your own recipe, you have two novel ways of doing this, first use socket.io , with this method let each page publish and subscribe to events, whenever one page emits a event, the other automatically receives it and vice versa. The alternative approach is to utilize node local storage and cache system modules. For local storage you can memcache, node-cache just do a npm search. For a fast and direct caching use redis,redis in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries.

Happy Coding :):

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda