I would like to make a django custom tag to display 10 entry titles from the category where the user is reading an article. How can I do this? I need to pass the category from the actual entry.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The best way to do this would be with an inclusion tag. This is a tag that renders a template fragment which renders the 10 related articles.
You just pass in the current article into the tag, and return the context for the template fragment – ie the related articles.
You’ll need a related_articles.html file in your templates directory which outputs the articles. Then, to call it from your main template, you would just do
where
articleis the name of the article object.