Dynamic content in single layout JS

Hello,

as one can see, there is the icon for dynamic content at the JS for pages or any other cornerstone document.

Can that be used to insert dynamic content… e.g. from ACF into a javascript?

In my case I want to be able to change the parsing level for h-tags at this js line:

$('#article').find('h2, h3').each(function(index) {

and replace it with a value set by using ACF when editing posts… eg by using:
{{dc:acf:post_field field="toc_level"}} - which would then have the values “h2”, “h2, h3” or “h2, h3, h4”

best regards
Mirco

Hey Mirco,

Thanks for writing in!

You can try this:
$('#article').find('{{dc:acf:post_field field="toc_level"}}').each(function(index) {

assuming that the ACF will return comma separated values.

Best Regards.

Hi @ruenel

I’ve already tried that and the output was just the the dc string, but not the value. I thought I may have messed up the " or ’ somehow :slight_smile:

From the source code:

Using the {{dc:…}} gives a correct output when using it at a text element:

I also tried to put a whole simple little JS command via a {{dc:…}}, but at the source code the output also was just the {{dc:…}} string and it gives me a code warning at the JS editor:


The simple JS is just an alert("Test") I

best regards
Mirco

Hello Mirco,

I tested it on my end and replicated the issue. I suspect it might be a bug of the latest release I went ahead and reported it to our development team. I would request you, please stay tuned for succeeding theme updates.

Thanks for understanding

1 Like

Good to see, that this was fixed with the latest update :slight_smile:

Thanks a lot!

1 Like

Awesome to hear. Have a great day.

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