I feel like everytime I post something I answer to muself lol, maybe not enough time, anyway, this is not on the forum like this anywhere so it’s worth adding, for another front-end noob like me
This is how you can get your posts with a specific tag:
This way you make sure that if your tag doesn’t have any posts you don’t show the tag title in there. Like you have in your picture for Nature and Advertising.
I’m not repeating my code at all. First foreach is for tags and the second one is for posts.
“just for better time complexity”. Not at all. You code is hard to maintain. If you want to do that for 10 tags you have to copy paste that code 10 times. Not good. This is why I did a get for tags and filter just the ones that I need. I would rather change a small array of slugs than copy paste a huge amount of code.
The way you check for featured posts is wrong. If you have 10 posts and in the first 4 there are no featured posts but in the remaining 6 you have some, your code will not display anything because you verify if the post is featured after you fetched it. Your get should be: {{#get "posts" limit="4" filter="tags:technology+featured:true" as |technology|}}
and without {{#if featured}}.
I encourage you give my version a chance and see that is easier to work with. You can just test it a little bit and see if you are confortable with it. It’s your code so you can delete it if you don’t want to use it anyway.
yeah true, I would have to copy the code jeje but for a huge db I guess it would be better than having 2 nested loops which is n^2. Anyway, I like your way because in my case that difference will happens in milliseconds, and I don’t have to repeat it.