pictures not working on meteor

Currently, I am working on a Meteor course that uses an older version of the platform. I find myself unsure about where to properly place files and folders within my project structure. In particular, I have images stored in a public folder located within my main directory along with the following client-side code found in main.html:

<head>
  <title>image_share</title>
 </head>
<body>
  <h1>Welcome to Coursera!</h1>

  {{>images}}

</body>

<template name="images">
    {{#each images}}
        <img src="{{img_src}}" height="100" alt="{{img_alt}}" />
    {{/each}}
</template>

In addition to this, there is also client-side code contained in main.js:

if (Meteor.isClient) {
    console.log("I am the client");

var img_data = [
    {
        img_src:"image1.jpg",
        img_alt:"dental surgery"
    },

    {
        img_src:"image2.jpg",
        img_alt:"carribean night"
    },

    {
        img_src:"image3.jpg",
        img_alt:"full moon palm tree"
    },

];

Template.images.helpers({images:img_data});
}

Unfortunately, I encountered an issue where only image1.jpg appears in the browser window.

Answer №1

Make sure your helpers are in the form of functions:

Template.pictures.helpers({
    pictures:function() {
        return data_images;
    },
});

Also, ensure that you are explicitly referencing the data within the loop using "this":

{{#each pictures}}
    <img src="{{this.picture_src}}" height="100" alt="{{this.picture_alt}}" />
{{/each}}

In this context, "this" represents the current object being iterated over in the array.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Enhancing User Experience with Multiple Conditional Checkboxes in jQuery

Having difficulty making a checkbox change some HTML content using JQuery. There is a standard html checkbox with the following attributes <input type="checkbox" name="AQN1" class="checkbox Q1" value="AQN10" id="3mcq"> <input type="checkbox" nam ...

Establish a JSONB index in Postgres for a sub-object within an array

My table myTable includes a JSONB column called myJsonb with a specific data structure that I wish to index, shown below: { "myArray": [ { "subItem": { "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemai ...

Include an index within the array

I need to incorporate an index in my array: Here is the loop I am using: for(j=0; j< data.data.tickets.length; j++) { var created_at = data.data.tickets[j].created_at; var tickettitle = data.data.tickets[j].subject; cleartab[requesterid]['t ...

Subset a 2-dimensional array by row to only include rows with a particular value

My goal is to subset 2D arrays of varying dimensions and extract only the columns that contain a 3 using the "any" function. While it works well with multiple columns containing a 3, it fails when there is only one or zero columns with a 3 present. Here&ap ...

Should a MEAN stack app require the use of two servers in order to run?

Currently, I am in the process of developing a MEAN stack application which involves using MongoDB, ExpressJs, Angular 6, and NodeJs. One issue I am facing is determining whether two servers will be necessary to run the app simultaneously. Specifically, o ...

`The select list is not responding to the change event being triggered`

Here is an example of HTML code: <select id="v_name" align="top"> <option value="server1">server1</option> <option value="server2">server2</option> </select> And here is the corresponding JavaScript code: < ...

The Vue BlogCards Component is missing from the display

My web app is designed to display blog posts in a grid layout. However, the BlogCards component in the Home.vue file is not showing any content as expected. The data is stored in firebase, and when I navigate to /blogs, I can see the blogs displayed in a g ...

Tips for adding a search bar to a material-ui MenuItem?

Can someone guide me on how to add a search input within the component? I reviewed the material-ui documentation, tried various approaches, but haven't been successful yet. Here's the code for the demo What I attempted: const searchBar = `${& ...

My Gatsby website is being rendered in its HTML form on Netlify

The website build is located at . It appears that the javascript functionality is not working, and only the html version (usually meant for search engines) is being displayed. It seems like this issue is only affecting the home page. You can check out the ...

A guide on transferring received data from dataService within the parent component to the child component in Angular2

Within the context of my application, there exists a parent component named app-parent and a child component called app-child. In app-parent, I retrieve data from a DataService. @Component({ selector: 'app-parent', providers: [DataService] ...

Building a JSON data stream with PHP To be Compatible With JQuery

A Solution: The issue was resolved by removing: echo '{"results":'.json_encode($arr).'}'; and replacing it with echo json_encode($arr); In addition to changing these lines: var items = []; $.each(data, function(key, val) { ...

Display a popup on a button click or icon click in ASP.NET

On Facebook, you may notice that you have 4 friend requests or notifications in the small mail icon on the right side. When you click on it, a pop-up appears with an accept button, and once you accept, it disappears and the remaining three requests are sho ...

Issue with bidirectional binding on angular material slide toggle not functioning as anticipated (Angular 4)

My angular material slide-toggle implementation seems to be working, but I'm facing an issue where it doesn't bind the value to the relevant variable as expected. // other irrelevant imports above.. import {MatDialog, MatDialogRef, MAT_DIALOG_DA ...

What is the method to assign an initial value to React.createRef()?

Scrolling management in my component is handled through a ref that represents the current scroll value. I've chosen to use refs instead of state and setState because using setState while the user is scrolling would result in a choppy and unresponsive ...

Instructions on how to open the <details> element from a link on a different page

Imagine a scenario where you have a Home Page with a link to a second page that features some content enclosed by a <details> element. However, the <details> element on the second page is initially closed, and you wish for the link on the home ...

Using a C-style string as an argument for a template function

I'm puzzled by the behavior of my program. According to my understanding, template argument deduction typically allows only two types of conversions: 1) array- or function-to-pointer conversions and 2) const conversions. In the code snippet below, a c ...

Determine the presence of a value within an array

Imagine I have the following: $A = "1,2,3,4"; $B = "2"; What is the best way to check if $B is present in $A? UPDATE: In reality, $A is actually an array in my program: $A = array(1,2,3,4); $B = "2"; ...

Is it possible to use a single function to both set the state and return JSX?

I'm currently grappling with creating a function that, when called, will update the state to an object {item: 'whatever the user types', list: [...list, todo]}. The challenge I'm facing is figuring out how to update the state and return ...

How to Properly Implement app.use() in Express for Middleware

What is the reason behind some middleware functions being passed in with invocation parentheses, while an anonymous function is passed in without being invoked? app.use(logger()); app.use(bodyParser()); If logger() is evaluated immediately and the return ...

JavaScript unable to locate wasm file

I am currently working on creating a WebAssembly (wasm) example from Rust by following this example. After running the command: cargo build The output included libdom.d and libdom.so files in the target/debug/ directory. To start the application, I u ...