Is it possible to filter entries based on entry table field values?
I have an entry called "reviews" and within reviews I have a table field with several values. I would like to use the field values to display entry listings in a particular way.
First: I would like to be able to display entry listings so that if the field value is = x to display a particular set of entries.
Second: I would like to be able to display these values so that they are in an ascending order.
craft3
New contributor
add a comment |
I have an entry called "reviews" and within reviews I have a table field with several values. I would like to use the field values to display entry listings in a particular way.
First: I would like to be able to display entry listings so that if the field value is = x to display a particular set of entries.
Second: I would like to be able to display these values so that they are in an ascending order.
craft3
New contributor
add a comment |
I have an entry called "reviews" and within reviews I have a table field with several values. I would like to use the field values to display entry listings in a particular way.
First: I would like to be able to display entry listings so that if the field value is = x to display a particular set of entries.
Second: I would like to be able to display these values so that they are in an ascending order.
craft3
New contributor
I have an entry called "reviews" and within reviews I have a table field with several values. I would like to use the field values to display entry listings in a particular way.
First: I would like to be able to display entry listings so that if the field value is = x to display a particular set of entries.
Second: I would like to be able to display these values so that they are in an ascending order.
craft3
craft3
New contributor
New contributor
New contributor
asked 9 hours ago
Aleks P
112
112
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
OK, one possible way is the use the value of the colour field in an if statement, something this:
{# list rows that have "blue" in the colour field #}
{% for row in table.fieldName %}
{% if row.colour == 'blue' %} // probably best to make "blue" a variable
<li>{{ row.age }} - {{ row.provider }} - etc.</li>
{% endif %}
In order to sort the table by a field value you will have to create a new array with the table data, then order by the name value. Will work that up for you in a bit
You could also do it with JavaScript, but that is nasty.
Here is the complete code using an Array to sort by the age field:
{% set tableBlock = %}
{% set tableRow = %}
{% for row in entry.myTableField %}
{% if row.colour == "blue" %}
{% set tableRow = {
'age' : row.age,
'colour' : row.colour,
'provider' : row.provider
} %}
{% set tableBlock = tableBlock|merge([tableRow]) %}
{% endif %}
{% endfor %}
{% for row in tableBlock|sort %}
{{row.age}} {{row.colour}} {{row.provider}}
{% endfor %}
For some reason the code block formatting is not working...
add a comment |
I think you will need to be more specific, perhaps give a code example?
@RoiAgenta My entry type name is "reviews" and I have created a table field with the handle "reviewData". Within this table are a few columns columns with the handle names "age, provider, colour, style". As per my first question I would like to display all review entries with the colour = "blue" in one listing. For the second question I would like to display all review entires in ascending order according to their age value.
– Aleks P
7 hours ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "563"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Aleks P is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcraftcms.stackexchange.com%2fquestions%2f28976%2fis-it-possible-to-filter-entries-based-on-entry-table-field-values%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
OK, one possible way is the use the value of the colour field in an if statement, something this:
{# list rows that have "blue" in the colour field #}
{% for row in table.fieldName %}
{% if row.colour == 'blue' %} // probably best to make "blue" a variable
<li>{{ row.age }} - {{ row.provider }} - etc.</li>
{% endif %}
In order to sort the table by a field value you will have to create a new array with the table data, then order by the name value. Will work that up for you in a bit
You could also do it with JavaScript, but that is nasty.
Here is the complete code using an Array to sort by the age field:
{% set tableBlock = %}
{% set tableRow = %}
{% for row in entry.myTableField %}
{% if row.colour == "blue" %}
{% set tableRow = {
'age' : row.age,
'colour' : row.colour,
'provider' : row.provider
} %}
{% set tableBlock = tableBlock|merge([tableRow]) %}
{% endif %}
{% endfor %}
{% for row in tableBlock|sort %}
{{row.age}} {{row.colour}} {{row.provider}}
{% endfor %}
For some reason the code block formatting is not working...
add a comment |
OK, one possible way is the use the value of the colour field in an if statement, something this:
{# list rows that have "blue" in the colour field #}
{% for row in table.fieldName %}
{% if row.colour == 'blue' %} // probably best to make "blue" a variable
<li>{{ row.age }} - {{ row.provider }} - etc.</li>
{% endif %}
In order to sort the table by a field value you will have to create a new array with the table data, then order by the name value. Will work that up for you in a bit
You could also do it with JavaScript, but that is nasty.
Here is the complete code using an Array to sort by the age field:
{% set tableBlock = %}
{% set tableRow = %}
{% for row in entry.myTableField %}
{% if row.colour == "blue" %}
{% set tableRow = {
'age' : row.age,
'colour' : row.colour,
'provider' : row.provider
} %}
{% set tableBlock = tableBlock|merge([tableRow]) %}
{% endif %}
{% endfor %}
{% for row in tableBlock|sort %}
{{row.age}} {{row.colour}} {{row.provider}}
{% endfor %}
For some reason the code block formatting is not working...
add a comment |
OK, one possible way is the use the value of the colour field in an if statement, something this:
{# list rows that have "blue" in the colour field #}
{% for row in table.fieldName %}
{% if row.colour == 'blue' %} // probably best to make "blue" a variable
<li>{{ row.age }} - {{ row.provider }} - etc.</li>
{% endif %}
In order to sort the table by a field value you will have to create a new array with the table data, then order by the name value. Will work that up for you in a bit
You could also do it with JavaScript, but that is nasty.
Here is the complete code using an Array to sort by the age field:
{% set tableBlock = %}
{% set tableRow = %}
{% for row in entry.myTableField %}
{% if row.colour == "blue" %}
{% set tableRow = {
'age' : row.age,
'colour' : row.colour,
'provider' : row.provider
} %}
{% set tableBlock = tableBlock|merge([tableRow]) %}
{% endif %}
{% endfor %}
{% for row in tableBlock|sort %}
{{row.age}} {{row.colour}} {{row.provider}}
{% endfor %}
For some reason the code block formatting is not working...
OK, one possible way is the use the value of the colour field in an if statement, something this:
{# list rows that have "blue" in the colour field #}
{% for row in table.fieldName %}
{% if row.colour == 'blue' %} // probably best to make "blue" a variable
<li>{{ row.age }} - {{ row.provider }} - etc.</li>
{% endif %}
In order to sort the table by a field value you will have to create a new array with the table data, then order by the name value. Will work that up for you in a bit
You could also do it with JavaScript, but that is nasty.
Here is the complete code using an Array to sort by the age field:
{% set tableBlock = %}
{% set tableRow = %}
{% for row in entry.myTableField %}
{% if row.colour == "blue" %}
{% set tableRow = {
'age' : row.age,
'colour' : row.colour,
'provider' : row.provider
} %}
{% set tableBlock = tableBlock|merge([tableRow]) %}
{% endif %}
{% endfor %}
{% for row in tableBlock|sort %}
{{row.age}} {{row.colour}} {{row.provider}}
{% endfor %}
For some reason the code block formatting is not working...
edited 6 hours ago
answered 7 hours ago
Roi Agneta
6762616
6762616
add a comment |
add a comment |
I think you will need to be more specific, perhaps give a code example?
@RoiAgenta My entry type name is "reviews" and I have created a table field with the handle "reviewData". Within this table are a few columns columns with the handle names "age, provider, colour, style". As per my first question I would like to display all review entries with the colour = "blue" in one listing. For the second question I would like to display all review entires in ascending order according to their age value.
– Aleks P
7 hours ago
add a comment |
I think you will need to be more specific, perhaps give a code example?
@RoiAgenta My entry type name is "reviews" and I have created a table field with the handle "reviewData". Within this table are a few columns columns with the handle names "age, provider, colour, style". As per my first question I would like to display all review entries with the colour = "blue" in one listing. For the second question I would like to display all review entires in ascending order according to their age value.
– Aleks P
7 hours ago
add a comment |
I think you will need to be more specific, perhaps give a code example?
I think you will need to be more specific, perhaps give a code example?
answered 8 hours ago
Roi Agneta
6762616
6762616
@RoiAgenta My entry type name is "reviews" and I have created a table field with the handle "reviewData". Within this table are a few columns columns with the handle names "age, provider, colour, style". As per my first question I would like to display all review entries with the colour = "blue" in one listing. For the second question I would like to display all review entires in ascending order according to their age value.
– Aleks P
7 hours ago
add a comment |
@RoiAgenta My entry type name is "reviews" and I have created a table field with the handle "reviewData". Within this table are a few columns columns with the handle names "age, provider, colour, style". As per my first question I would like to display all review entries with the colour = "blue" in one listing. For the second question I would like to display all review entires in ascending order according to their age value.
– Aleks P
7 hours ago
@RoiAgenta My entry type name is "reviews" and I have created a table field with the handle "reviewData". Within this table are a few columns columns with the handle names "age, provider, colour, style". As per my first question I would like to display all review entries with the colour = "blue" in one listing. For the second question I would like to display all review entires in ascending order according to their age value.
– Aleks P
7 hours ago
@RoiAgenta My entry type name is "reviews" and I have created a table field with the handle "reviewData". Within this table are a few columns columns with the handle names "age, provider, colour, style". As per my first question I would like to display all review entries with the colour = "blue" in one listing. For the second question I would like to display all review entires in ascending order according to their age value.
– Aleks P
7 hours ago
add a comment |
Aleks P is a new contributor. Be nice, and check out our Code of Conduct.
Aleks P is a new contributor. Be nice, and check out our Code of Conduct.
Aleks P is a new contributor. Be nice, and check out our Code of Conduct.
Aleks P is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Craft CMS Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcraftcms.stackexchange.com%2fquestions%2f28976%2fis-it-possible-to-filter-entries-based-on-entry-table-field-values%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown