Skip Navigation

[Resolved] Are arguments passed to render_view() available in nested views

This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by Minesh 6 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#689852

I am calling a view through render_view($args) in php.

This view selects and displays the body of a custom post that has itself a [wpv-view name="myNestedView"] in it.

This nested view tries to filter posts based an attribute set in $args but it does not seems available through VIEW_PARAM("myArgsAttribute") filter query.

In other words, the following is being performed :
- A bunch of attributes are set in $args, including title="myParentViewName".
- render_view($args) is being called from php, rendering "myParentViewName".
- myParentViewName selects a post through the filter using a value in $args, and displays the post body
- That post body contains a wpv-view shortcode calling a child view "myNestedView".
- That child view does not seem to have access to attributes set in $args.

Should I expect the nested view to have access to all the attributes set in $args?

If so, what am I doing wrong? What would be the workaround?

Thank you

François

#690308

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Could you please share the code you are trying to use and I would like to know which arguments you want to pass to nested view and how you pass it?

#692491

Here is the code :


$args = array(
    'title' => 'myParentViewName',
    'myattribute1' => 'myvalue1',
    'myattribute2' => 'myvalue2',
);
render_view( $args );

myParentView

Query filter myCustomPostField1 == myattribute1
Displays [wpv-post-body view_template="None"] of the selected post that matches the query above
The child view shortcode is located in the body of the post displayed by the parent view.

myChildView

Query filter myCustomPostField2 == myattribute2 {{is myattribute2 supposed to be available in this context???}}
Display [wpv-post-body view_template="None"] 

I'm sorry there is no easy ways to really copy and paste my exact code, as I have about 100's arguments generated programatically from an graivty forms entry object. However, my $args are 100% passing to my "parent view" no problem there. My question is about if those $args will be passed or not to a child view, when that child view is called from a shortcode located inside the body of a post selected by a parent view.

I want to do that:

render_view($args) => [wpv-post-body] => [wpv-view] => {{are $args still supposed to be available here???}}

I am not doing :

render_view($args) => [wpv-view] => content is returned

In other words, the parent view does not call directly the child view in the "Loop Ouput Editor". It calls the body of a post that has a view shortcode. Again, while this works, it does not seems like $args follow all the way through.

Please answer the specific question. Are $args supposed to be passed to the child view in that situation?

Thank you,

François

#696333

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

View's offer shortcode [wpv-attribute name="your-attribute-name"]

For example - you pass the view argument with name "location" which has value assigned "Boston":

[wpv-view name="houses" location="Boston"]

You can access the value of the location attribute with this shortcode:

[wpv-attribute name="location"]

Could you please try this - above solution should work for you.

More info:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-attribute

#697342

Hello,

I'm well aware of how to pass attributes to view short codes, and how to retrieve the value.

But this is not my question. I am asking about nested views, not about basic retrieval of attributes through short-code.

Would you mind passing over my question to one of your colleague? Maybe my explanations would resonate more with someone else.

Thanks

François

#700398

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Doh, my bad - somehow I managed to miss the last 7 lines of your previous reply where you explain main part and described where you added the view in your long reply.

Ok - so in situation when you have added the child view in post body I do not see its possible as you can access the passed argument to view's in scope of view not post body.

Please check the "context" - you can fetch the view's shortcode attribute within view's context:
=> https://toolset.com/documentation/user-guides/views-shortcodes/#vf-309292

There is no such feature available to fetch view's shortcode attribute from post body and again when its added as nested view.