1

We've set up a template to download an .xsl file of entries in a number of specific categories (with much help in this SE thread) - all works fine if we hardcode the category ID but if we tray to make the template dynamic by getting the category ID from the URL segment it fails (see below).

Is it possible to dynamically set the Category ID like this? Or any other way?

{exp:http_header 
    content_disposition="attachment" 
    filename="myfile.xls" 
    content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
}
<table>
<tbody>
{exp:channel:entries channel="my channel" category="{segment_3}" disable="category_fields|member_data|pagination"
}
<tr>
<td>{title}</td>
<td>{field_one}</td>
<td>{field_two}</td>
</tr>
{/exp:channel:entries}
</tbody>
</table>
4
  • 1
    "It fails" how? Can you please, update your answer with more details? – Sobral Jan 21 '15 at 22:51
  • Ah yes, if I hardcode it then it downloads the Excel file with all the correct data (minus cell borders - just un-bordered cells on a white background but that's ok) but if the Cat ID is taken via {segment_3} which is where the ID number is in the url, then it downloads the .xls file but it is blank containing no data. – segovius Jan 21 '15 at 22:58
  • 1
    I think i found the issue. Please, help me a little more. Does the URL used on the hard coded category test have a segment_3? Or, for the test, it just has the segments 1 and 2? – Sobral Jan 22 '15 at 1:45
  • It's just one segment it's using - the last one Segment_3 - I'm always passing the third segment for the test – segovius Jan 22 '15 at 8:15
2

It should work fine. You're just missing a dynamic="no" on your channel:entries tag.

Try it like this:

{exp:channel:entries 
    channel="my channel" 
    category="{segment_3}" 
    disable="category_fields|member_data|pagination" 
    dynamic="no"
}
1
  • That's the one! Great! – segovius Jan 22 '15 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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