How can I make variables from 1 file present in another
app.js
export async function main() {
try {
const accessToken = await getAccessToken();
const episodes = await getShowEpisodes(accessToken, showId);
//get episodes names
console.log('Show Episodes:', episodes);
//name is a property in an array
const episodeNames = episodes.map(obj => obj["name"]);
console.log(episodeNames);
return episodeNames;
} catch (error) {
console.error('An error occurred:', error.message);
}
}
main()
episodeList.astro
---
import Layout from '../layouts/Layout.astro';
import Navbar from '../components/Navbar.astro';
import Card from '../components/Card.astro';
import {main} from '../utils/app.js'
---
<Layout title="Episodes" >
<div class="bg-slate-900">
<Navbar />
<h1 class="text-white">this is good</h1>
<div class="text-white">
{main }
</div>
</div>
<!-- <Card href='' title=
${name} body='body of your mom' /> -->
</Layout>
<script>
import '../utils/app.js'
</script>
How can i print the values of episodeName(app.js) in episodelist.astro
I want episodelist.astro to be an index of episodes17 Replies
use a map??
I'm not really familiar with astro. What happens if you call
main
from within episodeList.astro
at the top and store the result as a variable that gets used by the markup? Also yeah, you will probably have to map over it since it's an arrayI am pretty sure it just replaces the
{main}
place holder with the return value of main
. So The return value must contain the markup
for the list. Or at least that is what I think 🤔map over the return value to generate the markup within
episodeList.astro
Love how astro works similar to JSX
the maps not working idk
yeah, i'm gonna have to try it out 0.o
would you post your code? kinda hard to help without that lol
@rooook
Check images for better view
that doesn't contain any mapping in the astro file, i'm asking to see what you tried
Ohh
if you'd use the code blocks (```js and ```) instead of regular code with a single `, you'd get highlighting in Discord
Thanks
Didn't know
make sure to read #How To Ask Good Questions, it has many more tips
Map function not working(if the map is suitable function for it pls help me with the code).
should i put all my app.js into top level episodeList.astro
like i've said, it's hard to help without seeing what you've tried