I have a portfolio page where every project has one or more tags.
The tags from each project should be shown both in an overview (foreach project: img, title, tags) and in the project page itself - plus i want to list all tags inside the footer which will be seen on every page.
This is the link I put both in the template projects (the overview) and in the template project (the project page). The docs say that I need a controller but as far as I understand controller are template related… My tags should be clickable from everywhere and then be shown as a overview-like page, which has a title saying “tagname” and then showing all projects connected to this tag I initially clicked on.
so far… I hope you understand what I want to achieve and maybe someone can help me!
thanks!
Your links have to reference the page where you want to show your results, presumably the projects overview page, where you then either show all projects or projects filtered by tag.
You can do the filtering in a template, but it would be better if you use a controller, in your case that would be the projects.php controller for the projects.php template. As regards the filtering itself, there is a cookbook recipe to the rescue.
Edit: it does not matter where you want to show the tags as long as the links you generate are correct.
I got one follow-up php question then: is it possible to combine foreach and if statements?
Currently my projects/overview code snippet looks like this:
Yes, of course, you can use if statements in a foreach loop and vice versa depending on your needs.
There’s a problem in your code, though. You use the $project variable at the top of the code, but it is only defined later in your foreach loop. You will have to move that line somewhere after the first foreach loop
into my foreach loop. So that the loop shows all projects, except there are tags inside the URL (then only show the ones with this specific tag) - am I thinking this the right way? Or do I need the controller here?
My controller looks like this: there must be something wrong because I actually don’t even understand what the controller is about and when I click on a tag it results in an error-page
As I used the projects overview as a snippet both on homepage and on projects page, I need to have two controllers with the same content for home-template and for projects-template.