Passing parameters/values into a Component Shortcode for use as dynamic content

Hello!

I am attempting to inject values into a component shortcode, but I’m not having any luck in being able to have those values be populated within the component itself.

$parameters = wp_json_encode([
        'Icon'     => $banner['icon'],
        'Headline' => $banner['headline'],
        'Description'  => $banner['description'],
        'CTA Button Text'  => $banner['cta_button_text'],
        'CTA Button Icon'  => $banner['cta_button_icon'],
        'CTA Button URL'  => $banner['cta_button_url']
    ]);

    echo do_shortcode("[cs_component id='PEXTzcB9TSOxPh6ejb' parameters='".$parameters."']");

In my component, I would then expect to be able to reference the keys of those parameters as dynamic values:

{{dc:param:Icon}}
{{dc:param:Headline}}
{{dc:param:Description}}
{{dc:param:CTA Button Text}}

In the documentation it has the following example use:

<!-- This example is for a component with a parameter called "text" -->

<!-- From a parameter JSON -->
[cs_component id="..." parameters='{ "text": "This is parameter data" }']

Well, detailing out this post seems to have done the trick haha… I’ve got it working per the items displayed above. I figured it’d be better to not delete it as it may be a helpful reference to others needing to do this. Thanks for creating such an awesome theme!

Hi @nickrouty,

Glad that you are able to find the solution and shared it with others.

Thanks

Hey @nickrouty,

Thanks for providing this! I found references the dynamic content and the shortcode you provided but not the code in which you create the $parameters variable.

I have spent the last hour trying to make the shortcode work but I’m not sure what’s missing. Per the shortcode document, the shortcode itself can take JSON values but the example doesn’t provide the whole picture it seems.

Do you have to write a function like you did in order for this to work?

Thanks

Hey @kgpthemex,

As we await a response from @kgpthemex, it would be beneficial for us to examine your setup in order to investigate the issue further. If you don’t mind, could you kindly provide us with your credentials and open a new thread? To ensure the security of your information, please share the requested details in a Secure Note.

  • WordPress Login URL
  • Admin level username and password
  • Components in question

You can find the Secure Note button at the bottom of your posts.

Thank you.

@kgpthemex The code that I used to generate the JSON is included within the original post. I’ve just passed a standard key/value array into the wp_json_encode function and then passed that as shown into the shortcode. You’ll want to be cautious of the output of the values of your JSON though as I did find that it was not being escaped correctly in certain output such as quotes.

Hey @nickrouty,

Thanks for sharing again your idea, @kgpthemex, hope that clarifies everything.

Cheers!

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