Ditto even provides a specific tagging module and dedicated parameters. As an alternative to defining an extra template Variable it also supports using Evo admin interface's keywords as tags, resulting in a better integration between the snippet and the core CMF modules, and an easy way to avoid tags proliferation for similar terms entered by different editors.
A Method of Tagging Blog / News Entries Where One Post May Belong To More Than One Category
For this example, we want the following categories:
- world news - all news items,
- local city news,
- news about bar1,
- news about bar2,
- news about art books & music
Users should be able to view general news (as the home page), local news, or specific news for only one place.
Create a TV checkbox called "categoryOptions" with input option values
"World||City||Bar1||Bar2||ArtBooksMusic" and assign it to the template that blog entries use. What this TV does is insert these checkboxes into all pages that use the assigned template.
Note: you will see these checkboxes when you are logged in to the Evo admin interface and editing a specific page. Some front-end snippets can also use this TV. You do not need to display this TV in the template, as it would just display as a string of values.
Create a folder called "Blogs" and uncheck show in menu.
To make a new blog post about an art exhibition in Bar1, create a new page called "Art Show Bar1" inside the "Blogs" folder in the Evo admin interface, and check the checkboxes: "Bar1" and "ArtBooksMusic".
If you call the "tvcategoryOptions" in the page content the output string will be "Bar1ArtBooksMusic" all joined together, which is not very useful. So we need to edit the "categoryOptions" TV and add a widget to separate each option, the widget that we need is called "Delimited List" and simply selects it from the dropdown menu. Then we need to specify what will separate each item. Simply add a comma as the value for the delimiter. Save and the TV is ready.
Now create a folder to hold the news category pages, and check "show in menu". This folder will be the main news called "World" (or Home) and it will show all news. Inside, create pages "City", "Bar1", "Bar2", "Art Books & Music".
Now to retrieve the right blog entries for each of the categories use a Ditto call with a slightly different
&tags. Be sure to set
&tagDelimiter to `,` so that it corresponds to what we set in the TV, and it knows how and where to split up the categories names / tags.
You also need to set
&tagData=`tvcategoryOptions` so that it know where to get the info about the tags, in this case from our TV "categoryOptions". We also need to set
&tagMode to "onlyTags". There are two options you could go with here for
&tagMode (both look similar but act very different): "onlyTags" and "onlyAllTags", the difference will be very clear in a moment…
Now for the "world, show all", make the
&tags check if any of these category tags are selected to display blogs (also &startID is the id of the folder containing all of the blogs):
[!Ditto? &startID=`2` &summarize=`5` &total=`20` &tpl=`ditto_articles` &paginate=`1` &alwaysshow=`1` &sortBy=`createdon` &sortDir=`DESC` &trunc=`1` &truncLen=`300` &commentsChunk=`` &displayArchive=`1` &paginateAlwaysShowLinks=`1` &descendentDepth=`1` &tagDelimiter=`,` &tagData=`tvcategoryOptions` &tagMode=`onlyTags` &tags=`World,City,Bar1,Bar2,ArtBooksMusic` !]
So if you went to this page it should be displaying the page created before, "Art Show Bar1", where we selected the checkboxes "Bar1" and "ArtBooksMusic". However if we had set
&tagMode=`onlyAllTags` nothing would be displayed, because it changes the Ditto call to only display blog entries that have ALL of these tags, whereas
&tagMode=`onlyTags` says display blog entries that have ANY of these tags, which is what we want.
So for the city category we want to show blogs about "City", also blogs about "Bar1" and "Bar2" because they are in the city. (They should really have "City" checked anyway, but just to be sure, we can specify them).
[!Ditto? &startID=`2` &summarize=`5` &total=`20` &tpl=`ditto_articles` &paginate=`1` &alwaysshow=`1` &sortBy=`createdon` &sortDir=`DESC` &trunc=`1` &truncLen=`300` &commentsChunk=`` &displayArchive=`1` &paginateAlwaysShowLinks=`1` &descendentDepth=`1` &tagDelimiter=`,` &tagData=`tvcategoryOptions` &tagMode=`onlyTags` &tags=`City,Bar1,Bar2` !]
It is required to add "tv" before the name of the template variable when you're using it in a snippet call like these, if you forget this the TV will not be found and thus not shown.
Suggest an edit to this page.