3

Hopefully someone maybe able to help me with an issue I have recently discovered on a site I'm working on.

The outset is that I'm bringing through report data from a matrix field onto the page. Within said matrix is a field which defines what type of report it is, in my case its Land, Sea or Air. This field is using a radio button fieldtype to distinguish. Now in hindsight I could say use a different matrix field for each report type, but that ship has sailed unfortunately. The data is in a single matrix table and there's no going back. Putting the data into two extra matrix fields would take more time than I need to commit to this.

The problem is that when I come to display data on page, I open my matrix tag do the following

{report_articles}

{if report_type=="Land"}

Show the Land data

{/if}

{/report_articles}

This works fine and the correct data gets pulled through. However on looking at my source code, I have noticed a significant gap in my markup. My assumption is that previous rows are being brought through, their data is just not being displayed. So for example my matrix table may have 5 Land Reports, 5 Sea Reports and 5 Air Reports, and in that order too. If I try to load the Air Reports page (ie, the last few rows), it seems to pull through 10 previous rows before it, and this shows in the source code as a gap and will therefore slow down my page. My question is, Is there an easier way to approach this, or a way to avoid the impact that its having on my source code?

Any advice/help is much appreciated

1 Answer 1

4

You can use Matrix's search parameter to return only the rows of interest:

{report_articles search:report_type="=Land"}
  Show the Land data
{/report_articles}
1
  • You're welcome! The other benefit of using the search parameter instead conditional display of rows is that any count-related variables (such as total_rows) will actually reflect the output.
    – Alex Kendrick
    Commented Dec 19, 2013 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.