Feature Requests: Dynamic Content Provider like a shortcode

One of the best things about Pro is the ability to create your own loopers and fill them with data. I’ve done this many times and it’s really easy and ingenious to put your own data in the front end.

But there are a few cases where it would make sense to modify this function a bit.

As an example I would like to mention where I use a custom looper to load an array via the Flickr API and output it as a gallery. I also want to load the additional info about the album, which needs a separate API call. I had previously created this as shortcode, which only allows one return value. But I want to read the name and the number of photos from the API without doing the API call each time with a separate shortcode.

My current solution is to have a separate looper provider for the Flickr gallery and inside a second one that reads the gallery info. This nested provider of course only returns a single array with all the info I need.

In my case it works fine, my thought is, if I can’t create another provider for my own data list because of a special nesting, it would be great to be able to define an additional function that returns such data. I imagine an additional option below Provider and Consumer, which for example is called “Additional dynamic data” and can be added via the dynamic function just like other data fields from the list. It would be a kind of supershortcode that can provide multiple data at once.

What do you think about this?

Hi @Regnalf,

Thanks for the well-explained details of what exactly you are expecting. The Looper Provider has been added for specific purposes and it serving it properly, adding a new option would divert the functionalities.

But, the suggestion is quite good and it requires some investigation before being added as a Feature Request, I will check and forward it to our development team to check the possibilities to add it as Feature Request.

Thanks

Sorry for any confusion that may have arisen. I didn’t mean that the looper provider should be changed, it works as it should.

My basic idea was really just to provide additional dynamic data that doesn’t need to be in a looper via a function if you need it.

Because the nice thing about the dynamic data is that you can still design them in the builder and not, for example, by a shortcode are created ready for HTML.

So it would really be a separate functionality, independent of a looper.

Hi @Regnalf,

Thanks for the clarification.

Hi @Regnalf,

I wanted to chime in here with a bit of extra info here. You could setup a Looper inside a Global Block to isolate the behavior. I don’t see us adding any kind of additional data layer to Loopers. Everything really needs to be inside the Provider for it to work properly.

Something we are planning on doing is creating element level variables. Maybe this is what you’re referring to. You know the custom attributes control? Think of that, but instead of adding attributes to the DOM you’re just storing bits of data on the element. Then you can pull those out with Dynamic Content. So you could add variable to store a link on your section, but retrieve it in a button somewhere down in that element tree. This is a planned feature that will be part of Theme Options at the latest.

Another things you can do to get more milage out of loopers is use a Dynamic Content Looper Provider, and register your own dynamic content. It’s kinda a bit like custom loopers but the array comes from Dynamic Content instead of your custom provider.

Here’s an example of a custom Dynamic Content statement:

add_filter( 'cs_dynamic_content_custom', function($result, $field, $args = array() ) {

  if ($field === 'my_list') {
    return [
      [ 'title' => 'First' ],
      [ 'title' => 'Second' ],
      [ 'title' => 'Third' ],
    ];
  }

  return $result;

}, 10, 3);

Then you place {{dc:custom:my_list}} inside the field of a Looper Provider set to the Dynamic Content type.

Hopefully this helps give you some ideas.

Wow, thanks for that info @alexander. As I mentioned in my previous reply to Trisup, it’s not about changing the loopers.

My idea sounds more like what you wrote regarding the levels variables. I’m very curious about that already.

The thing with the “cs_dynamic_content_” is also great, just unfortunately again not included in the documentation. I really hope that a complete hook reference will come one day. As I see it, this dynamic content is then available for the entire page and not just for a specific element. This would be disproportionate for an API call that is only needed on a specific page.
If I ever need globally available dynamic content, I’ll be happy to use that.

But can you then also address individual fields like this?

{{dc:custom:myvars field="field1"}}

Many thanks, @Regnalf

Hi @Regnalf,

I don’t think we’ll ever have full documentation of hooks because it’s quite a bit to manage and keep accurate over time and many of our users prefer to avoid custom code. Yes, you can use $args for that. Let me change your field to key for the sake of this example since we consider “field” to be what comes after the colon.

add_filter( 'cs_dynamic_content_custom', function($result, $field, $args = array() ) {

  if ($field === 'data') {
    $data = [
       'title' => 'First',
       'date' => 'August 20, 2021'
    ];

    if ( isset($args['key']) && isset( $data[ isset($args['key'])]) ) {
     $result = $data[ isset($args['key'])];
    }

  }

  return $result;

}, 10, 3);

Now you can access that with {{dc:custom:data key="title"}} and “First” will be returned.

Thanks a lot that work perfect. Even if „other“ user just want to click and style I LOVE the ability to create custom loopers and style it in the builder. I don’t know if any other theme or builder out there can do this!

I’m exited to see the new element variables, will be there a beta where it is included?

Hello @Regnalf,

The Custom Looper Provider is already included in the latest release. We actually have had it since Pro 4.1.2 version. You can also check it in our documentation here:

As for new elements, yes they may be included in the next beta version. We do not have an ETA yet though.

Best Regards.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.