Joomlatools Pages also allows to filter directly on the Custom Fields!
This is not possible in Joomla without an extension and can be done directly via the Frontmatter or via the url
Filtering on Custom Field via url
Click on the following links and see the list of articles changing in function of the filter criteria.
- /filter-cf
- /filter-cf?field[socialbrusselsid]=13817
- /filter-cf?field[socialbrusselsid]=13817,3322 (which is an OR)
Note: You cannot yet use filter or use filter contraints like gte for article fields. This is a limitation: it is only supported by filter at the moment
The short of it is, filter works for base collections, but not for complex custom collections like the Joomla Extension which gets data from different database tables.
It works for:
- A single database table, if you use the database collection type
- A webservice, if you use the webservice collection type
- A file on the filesystem, if you use the filesystem collection type (Filesystem works like webservice but uses a file on filesystem, technically this also supports files from ftp, etc)
List of articles (filtered on CF):
- Organization 1 (socialbrusselsid: 13817)
Filtering on Custom Field via Frontmatter
---
@collection:
model: ext:joomla.model.articles
state:
sort: title
category: [organizations]
field:
socialbrusselsid: [13817, 3322]
---
About filtering for Custom Fields
- a (database) collection can define states: https://github.com/joomlatools/joomlatools-pages/blob/feature/175-joomla/contrib/extensions/joomla/model/articles.php#L16 and then it can implement rules how to handle those states, for example the field state is transformed into a query here: https://github.com/joomlatools/joomlatools-pages/blob/feature/175-joomla/contrib/extensions/joomla/model/articles.php#L176
- The filter state is an attempt to make this just work, so you don't need custom code. https://github.com/joomlatools/joomlatools-pages/blob/feature/175-joomla/code/site/components/com_pages/model/behavior/filterable.php It works great for data coming from webservices, or from arrays, for database this is a tad harder to implement, it works for data from the dame table, for related data it'es harrder. Still working on making it so that you don't need special states for filtering on db.
And here is a little var_dump(collection())
so that you can see all what is immediately available in the array itself:
object(ComPagesModelEntityItems)#1893 (1) {
[2]=>
array(25) {
["id"]=>
string(1) "2"
["slug"]=>
string(14) "organization-1"
["title"]=>
string(14) "Organization 1"
["summary"]=>
string(0) ""
["category"]=>
string(753) "object(ExtJoomlaModelEntityCategory)#2108 (16) {
["id"]=>
string(1) "8"
["slug"]=>
string(13) "organizations"
["title"]=>
string(13) "Organizations"
["summary"]=>
string(0) ""
["date"]=>
string(25) "2021-04-22T08:35:56+00:00"
["edited_date"]=>
string(25) "2021-04-22T08:35:56+00:00"
["author"]=>
string(3) "844"
["editor"]=>
string(3) "844"
["impressions"]=>
int(0)
["direction"]=>
string(4) "auto"
["language"]=>
string(1) "*"
["parent"]=>
NULL
["published"]=>
string(1) "1"
["image"]=>
array(0) {
}
["name"]=>
string(13) "Organizations"
["metadata"]=>
array(4) {
["og:title"]=>
NULL
["og:url"]=>
NULL
["og:image"]=>
NULL
["og:description"]=>
NULL
}
}
"
["tags"]=>
array(2) {
[0]=>
string(4) "tag1"
[1]=>
string(4) "tag3"
}
["date"]=>
string(25) "2021-04-20T08:38:13+00:00"
["edited_date"]=>
string(25) "2021-07-05T15:53:31+00:00"
["published_date"]=>
string(25) "2021-04-20T08:38:13+00:00"
["archived_date"]=>
NULL
["author"]=>
string(3) "844"
["editor"]=>
string(3) "844"
["image"]=>
array(3) {
["url"]=>
string(25) "/images/headers/maple.jpg"
["alt"]=>
string(5) "maple"
["caption"]=>
string(5) "maple"
}
["impressions"]=>
int(0)
["direction"]=>
string(4) "auto"
["language"]=>
string(1) "*"
["published"]=>
string(1) "1"
["archived"]=>
string(1) "0"
["trashed"]=>
string(1) "0"
["featured"]=>
string(1) "0"
["links"]=>
array(0) {
}
["ordering"]=>
int(1)
["fields"]=>
string(4061) "object(ExtJoomlaModelEntityFields)#2174 (4) {
["socialbrusselsid"]=>
array(14) {
["id"]=>
string(1) "1"
["name"]=>
string(16) "socialbrusselsid"
["title"]=>
string(18) "social.brussels ID"
["type"]=>
string(4) "text"
["label"]=>
string(18) "social.brussels ID"
["default"]=>
string(0) ""
["published"]=>
string(1) "1"
["required"]=>
string(1) "0"
["params"]=>
array(2) {
["filter"]=>
string(0) ""
["maxlength"]=>
string(0) ""
}
["group"]=>
NULL
["language"]=>
string(1) "*"
["multi"]=>
string(1) "0"
["ordering"]=>
int(1)
["value"]=>
string(5) "13817"
}
["youtube"]=>
array(14) {
["id"]=>
string(1) "2"
["name"]=>
string(7) "youtube"
["title"]=>
string(11) "YouTube URL"
["type"]=>
string(3) "url"
["label"]=>
string(11) "YouTube URL"
["default"]=>
string(0) ""
["published"]=>
string(1) "1"
["required"]=>
string(1) "0"
["params"]=>
array(2) {
["schemes"]=>
array(1) {
[0]=>
string(5) "https"
}
["relative"]=>
string(0) ""
}
["group"]=>
NULL
["language"]=>
string(1) "*"
["multi"]=>
string(1) "0"
["ordering"]=>
int(2)
["value"]=>
string(43) "https://www.youtube.com/watch?v=LXeaDPmHP18"
}
["repeatable"]=>
array(14) {
["id"]=>
string(1) "4"
["name"]=>
string(10) "repeatable"
["title"]=>
string(10) "Repeatable"
["type"]=>
string(10) "repeatable"
["label"]=>
string(10) "Repeatable"
["default"]=>
string(0) ""
["published"]=>
string(1) "1"
["required"]=>
string(1) "0"
["params"]=>
array(1) {
["fields"]=>
array(1) {
["fields0"]=>
array(3) {
["fieldname"]=>
string(4) "DATE"
["fieldtype"]=>
string(8) "calendar"
["fieldfilter"]=>
string(1) "1"
}
}
}
["group"]=>
NULL
["language"]=>
string(1) "*"
["multi"]=>
string(1) "0"
["ordering"]=>
int(3)
["value"]=>
array(0) {
}
}
["internal-link-reverse"]=>
array(14) {
["id"]=>
string(1) "5"
["name"]=>
string(21) "internal-link-reverse"
["title"]=>
string(21) "Internal Link Reverse"
["type"]=>
string(14) "articleslinked"
["label"]=>
string(19) "internallinkreverse"
["default"]=>
string(0) ""
["published"]=>
string(1) "1"
["required"]=>
string(1) "0"
["params"]=>
array(24) {
["filter_categories"]=>
string(1) "0"
["categories_inc_children"]=>
string(1) "0"
["filter_tags"]=>
string(1) "0"
["tags_inc_children"]=>
string(1) "0"
["filter_language"]=>
string(1) "0"
["language"]=>
string(5) "nl-NL"
["filter_users"]=>
string(1) "0"
["filter_customfields"]=>
string(1) "0"
["customfield1_id"]=>
string(0) ""
["customfield1_value"]=>
string(0) ""
["customfield2_id"]=>
string(0) ""
["customfield2_value"]=>
string(0) ""
["customfield3_id"]=>
string(0) ""
["customfield3_value"]=>
string(0) ""
["linked_articles_ordering"]=>
string(5) "title"
["linked_articles_ordering_direction"]=>
string(3) "ASC"
["linked_articles_ordering_2"]=>
string(7) "created"
["linked_articles_ordering_direction_2"]=>
string(4) "DESC"
["layout"]=>
string(5) "title"
["custom_field"]=>
string(0) ""
["link_title"]=>
string(1) "1"
["custom_html"]=>
string(36) "[title] ([hits])"
["use_separator"]=>
string(1) "1"
["separator"]=>
string(2) ", "
}
["group"]=>
NULL
["language"]=>
string(1) "*"
["multi"]=>
string(1) "0"
["ordering"]=>
int(4)
["value"]=>
string(1) "0"
}
}
"
["metadata"]=>
array(10) {
["og:type"]=>
string(7) "article"
["og:title"]=>
string(14) "Organization 1"
["og:url"]=>
NULL
["og:image"]=>
string(25) "/images/headers/maple.jpg"
["og:description"]=>
NULL
["article:published_time"]=>
string(25) "2021-04-20T08:38:13+00:00"
["article:modified_time"]=>
string(25) "2021-07-05T15:53:31+00:00"
["article:expiration_time"]=>
NULL
["article:tag"]=>
string(9) "tag1,tag3"
["og:locale"]=>
string(1) "*"
}
["name"]=>
string(14) "Organization 1"
}
}