Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I have a mongodb setup where there any documents for video games. Each document contains information about the game like the title, etc. I want to display each document as a card with html and css, displaying the information about it. Each card needs to have an image of the game on it, so I specified and image path as one of the categories in the document. Now I need to have an html class (the kind you would call to in a div) for each document so I can call that image path specified in that document to display that background for each card. How can I have a new html class made for every document in the database?

Here is some code I used:

HTML
<template name="popularGames">
  <div id="gameBackround" class="col-lg-2 popular-games view view-first">
    <div class="mask">
      <h2>{{title}}</h2>
      <p>Amount of groups playing this title now: 11,075</p>
      <a href="#" class="info">Join Lobby</a>
    </div>
  </div>
  <style>
    .popular-games{
      background-image: url( {{background}} );
      background-repeat: no-repeat;
      background-position: center;
      background-size: cover;
    }
  </style>
</template>


As you can see I am tried to use a background attribute from the mongodb document to change the background of an individual card but it changes the background for all the cards because all the cards are linked to one class, therefore one background. How can I have it so there is a class for every individual document?

What I have tried:

I have tried using meteor templates to add in the class and then edit the class with style tags but it this solution does not help really at all
Posted
Updated 8-May-16 17:43pm
v4
Comments
Sergey Alexandrovich Kryukov 8-May-16 21:10pm    
What is that, "HTML class"? Do you mean CSS and "class" attribute? Why for each document? It doesn't seem to make sense. If you think it makes sense, please explain your design.
—SA
Member 11912047 8-May-16 22:28pm    
I have a mongodb setup where there any documents for video games. Each document contains information about the game like the title, etc. I want to display each document as a card with html and css, displaying the information about it. Each card needs to have an image of the game on it, so I specified and image path as one of the categories in the document. Now I need to have an html class (the kind you would call to in a div) for each document so I can call that image path specified in that document to display that background for each card. Does that help?
Dave Kreskowiak 8-May-16 22:40pm    
Copying and pasting exactly what you have above doesn't improve the description at all. We need to know what you mean by "HTML class". Why does every "card" have to have it's own class?
Member 11912047 8-May-16 22:41pm    
i actually wrote the comment to him and then edited the question to put it into so it could help everyone else.... anyways, every card has to have its own class so every card can have its own background. i added some code above, maybe that will help
Sergey Alexandrovich Kryukov 8-May-16 22:45pm    
Sounds like a dreadful design. Anyway, it's reduced to the basic thing: where is the knowledge on what background and other stylistic elements should be for every record?
What is the content in {{ }}? Is it a kind of template in a template, or just some meta-notation you want to use to show your indent?.. Do you understand yourself how to use template elements?
And, finally, how do you use the database? What do you have on the server side?
—SA

1 solution

I don't think you want a unique CSS class for this.
If, and that is a big if, I have understood you correctly, you want to have the same style and layout for your HTML page, but with a different background image for the main <div> element.
So basically your CSS file should be static and not change for each game you want to show, only the background image of the <div> should change.

Have you tried do do something like this?
HTML
<div class="game" style="background-image:url( {{background}} )">
    <!-- Other elements-->
</div>


[EDIT] For some odd reason I typed 'removed' instead of 'url'. Must be lack of coffee.
 
Share this answer
 
v3
Comments
Member 11912047 9-May-16 20:07pm    
That's exactly what I was looking for, thanks so much! Happy coding.
George Jonsson 9-May-16 20:13pm    
Glad I could help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900