- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
export to template context question
SOLVEOct 10, 2018 2:32 PM
I have two blogs:
Default: Posts
Team Members: Member bios and contact information
On each bio (in Team blog) , I'm trying to display the 3 most recent posts by each member (found in Default blog.)
When I use the following code in the team blog post template, it works. I get the 3 recent results from john-doe.
{% set author_posts = blog_recent_author_posts('default', 'john-doe', 3) %} {% for author_post in author_posts %} <div class="post-title">{{ author_post.name }}</div> {% endfor %}
However, I need this to be team-member-specific.
So, to the Team Member blog page, I added a field to enter the author slug:
{% text "authslug" label="Author Slug", export_to_template_context=True %}
And I am able to output that value in my template with:
{{ content.widgets.authslug.body.value }}
EXCEPT, for when I try to put that code into the call for the 3 posts:
{% set author_posts = blog_recent_author_posts('default', '{{ content.widgets.authslug.body.value }}', 3) %} {% for author_post in author_posts %} <div class="post-title">{{ author_post.name }}</div> {% endfor %}
Any ideas on how to get the team member's author slug(from default blog) to output in the code above?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Accepted Solutions
Oct 12, 2018 1:05 PM - edited May 31, 2019 5:01 AM
@jestlinbaum you have a simple syntax error.
I can't impress with terminology, but basically you create a python 'environment' inside of code blocs wrapped in "{{ }}" or "{% %}". Creating an 'environment' inside of an 'environment' is redudant. Feel free to check me on my phrasing.
{% set author_posts = blog_recent_author_posts('default', content.widgets.authslug.body.value, 3) %} {% for author_post in author_posts %} <div class="post-title">{{ author_post.name }}</div> {% endfor %}
I removed the curlys and the quotes. Now you are essentially calling a variable inside of your code block instead of printing the string '{{content.widgets.authslug.body.value}}' which is what is happening in your code.
Need help? Hire Us Here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content