Ad

How To Modify JSON Structured Data Dynamically, Modify The Value Of Each Key Inside A Script Tag

- 1 answer

I need to add script inside a certain group of pages, how do i modify values of a key inside a script tag, does it have to be done in the server side or client side? When the user does view page source it should be able to see the certain values change from page to page.

this is the json structure


    {
                "@context": "https://schema.org",

                "@type": "Article",

                "mainEntityOfPage": {

                  "@type": "WebPage",

                  "@id": "{{location of the page }}"
},
              "headline": "{{Schema - Article Headline}}",

              "datePublished": "{{published_date}}",

              "dateModified": "{{modified_date}}",

               "description": "{{description}}"
}
</script>

I need to add location, published_date, modified_date, and description. can I do this in the client-side with javascript, or server-side with java servlets?

Ad

Answer

Can I do this in the client-side with javascript, or server-side with java servlets?

Yes. You can do it either client-side or server-side.

The code you posted looks like some client-side templating (Angular?). This would need to be parsed and filled-in by the client-side framework you’re using based on the data models you defined.

If you would like to do it server-side with HTL/Sightly you would need to replace {{expression}}s with HTL ${expression}s which would be filled in based on the defined HTL global objects or Use-Objects.

Ad
source: stackoverflow.com
Ad