I wanted to create a page that lists blog items that are of a specific tag.
I can see how to use blog.html.twig is doing that in users/themes/templates - what I cant figure out is how I get a root level page to be able to retrieve blog entries when its not associated with the blog?
My blog is my index page and then there are a couple of default pages - I want my blog-tag page to appear in the nav with these.
Not sure I understood what you want. Is it the list of pages with specific tag or a navigation item to one of the default pages? Could you post your pages structure with taxonomies and what exactly you want the result to be?
In theory I could alter the page /01.blog with the template blog.html.twig, and I could make it just display items with the tag ‘yellow’ right? I would have a new edited version of /01.blog
Now suppose I wanted to use both the unedited and edited versions of /01.blog? so my blog could both display all my blog posts as usual and on another blog page it could display only the posts with the ‘yellow’ tag.
Now suppose I want in our file structure /03. page 2, which is a flat default page to in fact show what the edited version of the blog posts is?
And I suppose a common sense explanation is that I have a blog currently with 4 main topics - this will expand. I want a page that has posts just from one topic - as its more important.
Im my case I have the topics design, building, apple, motorbikes - and I want a dedicated page for my most important topic - design.
Ok, sure that makes sense - this code I can see is what I want,
content:
items:
'@taxonomy.tag': design
But the confusing bit is how thats applied. Ive got my default page in the root. I can see its going in the .md file right? then which template is it using to display?
Whichever the file name matches. default.md uses default.html.twig, form.md uses form.html.twig. You can actually use same template to list different items.
@louigi, It will use the template as defined by the name of the page in which the collection is defined or it will use the variable ‘template’ in the page’s frontmatter.
Looking at your folder structure, I presume that will be template ‘blog.html.twig’.
Template ‘blog.html.twig’ is designed to use the collection defined in the frontmatter of a page and list the items in the collection.
If you are using a template that does not make use of a collection, you will have to update an existing template or create a new template similar to ‘blog.html.twig’
You can also create a collection inside Twig in any template (see docs on collections):
{% set collection = page.evaluate([{'@page.children':'/blog', '@taxonomy.tag':'photography'}]) %}
{% set ordered_collection = collection.order('date','desc') %}
OK, so forgive me here - Im not a developer, so some of it is a bit of a reach.
I can basically duplicate a template or make a new one with as you suggest using {% set collection = page.evaluate([{’@page.children’:’/blog’, ‘@taxonomy.tag’:‘photography’}]) %}
Then a page using the same name - and by page we mean a folder with the same name containing a .md file with the same name? and this file contains various switches to the template and other html and so on? Have I got that about right?
The basic problem was that I wasn’t updating the cache so the resultant page wasn’t reflecting changes in the template. its annoying to be stuck on that singular problem for quite a while when the solution was very simple.
As stated @anon76427325 - what you were suggesting is exactly right, the use of a custom template allowed me to use the code you suggested - although I changed it a bit, but its working just fine now.