Skip Navigation

[Resolved] Dynamic content in JS editor (content template)

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 3 replies, has 2 voices.

Last updated by Minesh 9 months ago.

Assisted by: Minesh.

Author
Posts
#2629023

Tell us what you are trying to do?
I am trying to add dynamic content into the content template's JS editor
Is there any documentation that you are following?
Can't seem to find any.

We are adding a shortcode for Rich reviews to the content template.
Since the Review code isn't wrapping the address, phonenumber, etc, I want to append them using jQuery.
But I can't seem to work out how to use dynamic content in the JS editor.

I've tried something like:
jQuery(document).ready(function(){
jQuery('[itemprop="address"]').append('<span itemprop="streetAddress">[tb-dynamic provider="__current_post" post="current" source="toolset_custom_field|field-group-for-restaurants" field="adres" force-string="first" ]</span>');
})
But the shortcode is shown instead of the dynamic value.

#2629057

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Can you please share details what field you want to append some value and what is your expected result and share problem URL and admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2629063
toolset-support.jpg

Hi Minesh,

Let me try to clarify.

We have set up a website listing several restaurants. Visitors can leave a review for each restaurant.
We installed a plugin (Rich Reviews by Starfish) to have this functionality.
To add the Rich review, we simply add a shortcode to the content template.

Everything is working fine so far.
The plugin also adds schema.org data, but since the rich review section is merely a small part of the page, the restaurants address, phone number, etc... are not inside the div that has the itemprop 'LocalBusiness' (hidden link).

Therfor, I want to append them (after the DOM has loaded) using jQuery.

To achieve this, I have to use a custom field in the content template's JS editor.

This is the script I'm using for the moment:
jQuery(document).ready(function(){

jQuery('[itemprop="address"]').append('<span itemprop="streetAddress">[tb-dynamic provider="__current_post" post="current" source="toolset_custom_field|field-group-for-restaurants" field="adres" force-string="first" ]</span>');

})

This is how the DOM looks after script execution:
<div itemscope="" itemtype="hidden link">
<span itemprop="name" style="display: none;">A'Sur</span>
<a itemprop="image" href="
hidden link"></a>
<div itemprop="address" itemscope="" itemtype="hidden link" style="display: none;">

<span itemprop="streetAddress">

[tb-dynamic provider="__current_post" post="current" source="toolset_custom_field|field-group-for-restaurants" field="adres" force-string="first" ]

</span>

</div>...

Instead of the actual address, the shortcode is rendered.

So my question.
Is it possible to use dynamic content in the content template's JS editor?
How can I achieve this?

If you want to check a restaurant listing, you can check this page: hidden link
I've added a screenshot to clarify the JS editor part in the content template as well.

#2629103

Minesh
Supporter

Languages: English (English )

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

The block should be rendered at server side and throw the rendered output on frontend. There is no way to render the block using javascript.

What if you allow and add the block in the backend and allow it to render on the page and try to get the element of that rendered output block and append your desired content to it - will that help?

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.