CMS Development

jestlinbaum
Participant

export to template context question

SOLVE

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?

 

 

0 Upvotes
1 Accepted solution
Jsum
Solution
Key Advisor

export to template context question

SOLVE

@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

View solution in original post

7 Replies 7
Jsum
Solution
Key Advisor

export to template context question

SOLVE

@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

jestlinbaum
Participant

export to template context question

SOLVE

@Jsum ah I see.

 

Your fix is working perfectly. Thank you so much!

tjoyce
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

export to template context question

SOLVE

@jestlinbaum - I'm not at computer right now but, I think there's an allWidgets index in the dict.

Try inspecting the data from 

{{content.allWidgets|pprint}}

see if it's in there.

0 Upvotes
jestlinbaum
Participant

export to template context question

SOLVE

@tjoyce yes it shows up. I can get the value to print anywhere EXCEPT in the call to the default blog.

 

I am on the Team Blog post template calling for articles from the Default Blog. When I put in the author slug it works correctly:

{% set author_posts = blog_recent_author_posts('5686817676', 'john-doe', 3) %}
{% for author_post in author_posts %}
<div class="post-title">{{ author_post.name }}</div>
{% endfor %}


But when I try to populate the author slug from the custom field in the Team Post it does not work:

{% set author_posts = blog_recent_author_posts('5686817676', '{{ content.widgets.authslug.body.value }}', 3) %}
{% for author_post in author_posts %}
<div class="post-title">{{ author_post.name }}</div>
{% endfor %}

'5686817676' is referencing the Default Blog. However '{{ content.widgets.authslug.body.value }}' is referencing a custom field from the Team Blog post (the template I am working in). I think that is why it is not working. I'm wondering if there is a workaround.

 

0 Upvotes
tjoyce
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

export to template context question

SOLVE

yea @jestlinbaum - this is a long shot but sometimes I have to do 

{{ content.allWidgets.authslug.body.value }}

aside from that, maybe @Jsum knows what's going on here. 

0 Upvotes
jestlinbaum
Participant

export to template context question

SOLVE

@tjoyce yes it shows up. I can get the value to print anywhere EXCEPT in the call to the default blog.

 

I am on the Team Blog post template calling for articles from the Default Blog. When I put in the author slug it works correctly:

{% set author_posts = blog_recent_author_posts('5686817676', 'john-doe', 3) %}
{% for author_post in author_posts %}
<div class="post-title">{{ author_post.name }}</div>
{% endfor %}

 


But when I try to populate the author slug from the custom field in the Team Post it does not work:

{% set author_posts = blog_recent_author_posts('5686817676', '{{ content.widgets.authslug.body.value }}', 3) %}
{% for author_post in author_posts %}
<div class="post-title">{{ author_post.name }}</div>
{% endfor %}

 

'5686817676' is referencing the Default Blog. However '{{ content.widgets.authslug.body.value }}' is referencing a custom field from the Team Blog post (the template I am working in). I think that is why it is not working. I'm wondering if there is a workaround.

 

0 Upvotes
jestlinbaum
Participant

export to template context question

SOLVE

@tjoyce yes it's in there. I am able to output the field anywhere in the template EXCEPT in the call to the other blog.

 

I am on the Team Blog post template calling for articles from the Default Blog. When I put in the author slug it works correctly:

 

{% set author_posts = blog_recent_author_posts('5686817676', 'john-doe', 3) %}
{% for author_post in author_posts %}
    <div class="post-title">{{ author_post.name }}</div>
{% endfor %}

But when I try to populate the author slug from the custom field in the Team Post it does not work:

 

 

{% set author_posts = blog_recent_author_posts('5686817676', '{{ content.widgets.authslug.body.value }}', 3) %}
{% for author_post in author_posts %}
    <div class="post-title">{{ author_post.name }}</div>
{% endfor %}

'5686817676' is referencing the Default Blog. However '{{ content.widgets.authslug.body.value }}' is referencing a custom field from the Team Blog post (the template I am working in). I think that is why it is not working. I'm wondering if there is a workaround.

 

0 Upvotes