Inserting dynamic data into a manifest.json

Im trying to use the data from my server connect to render in my manifest.json file.

PHP server model

The manifest is in my header.

<link rel="manifest" href="manifest.json">

At the top of my page i have
<html is="dmx-app" id="as" >

Say i have dynamic data {{companydetails.data.query1[0].name}} i tried to insert this in the json file, but it renders on the page as {{companydetails.data.query1[0].name}}. but outside of the json it “renders” perfectly.

my json file

    {
      "lang": "en",
      "dir": "ltr",
      "name": "{{companydetails.data.query1[0].name}}",
      "short_name": "{{companydetails.data.query1[0].name}}",
      "background_color": "red"
    }

Must i maybe add a delay before loading / linking the <link rel="manifest" href="manifest.json">

Would one need to create an extension for this to use data bind with it? @Teodor

You can’t use dynamic values like that in a separate json files, included on your pages.

Ok great. Can you please propose on how i can approach this please.?

Create a Server Action and use the Group step (hopefully that’s available on PHP) and Set Value to create your JSON object, and then use Response step to return such object

On your HTML do something like this:

<link rel="manifest" href="your/serveraction/manifest.json.php">

Edit: Actually, you don’t need the Group and Response steps, just use the Set Value steps

Set Value lang = "en"
// (...)
1 Like

very interesting… it makes sense the way you approach this because of the server connect api’s … thanks for the idea… let me have a go…

thanks… but no grouping in the php… as i can get all the text in the set values… but icons need to be in a group… but thanks that almost did the trick im sure

I didn’t understand if you solved the problem (without groups) :sweat_smile:

i guess i will have to manually edit the code if i want it to be in groups. because the ICONS is all in a group … eg…

The below is the original json file

{
"short_name": "test",
"name": "test",
"icons": [
    {
        "src": "/uploads/favicon-images/icon-192x192.png",
        "type": "image/png",
        "sizes": "192x192"
    },
	{
        "src": "/uploads/favicon-images/icon-256x256.png",
        "type": "image/png",
        "sizes": "256x256"
    },
    {
        "src": "/uploads/favicon-images/icon-512x512.png",
        "type": "image/png",
        "sizes": "512x512"
    }
],
"start_url": "/",
"background_color": "#3367D6",
"display": "standalone",
"scope": "/",
"theme_color": "#3367D6"

}

Does icons needs to be dynamic?

You can JSON minify:
https://codebeautify.org/jsonminifier
Becomes:

[{"src":"/uploads/favicon-images/icon-192x192.png","type":"image/png","sizes":"192x192"},{"src":"/uploads/favicon-images/icon-256x256.png","type":"image/png","sizes":"256x256"},{"src":"/uploads/favicon-images/icon-512x512.png","type":"image/png","sizes":"512x512"}]

You can then do Set Value:
Set Value icons = "[{"src": (...)"

You might have luck and find a JSON decode formatter as well

thank you… not the icons is static…

Weird… I can see all the data… as json…

https://www.auctionsoft-3.co.za/dmxConnect/api/FrontEnd/manifest.php from this location as its added in the

<script src="mainfestloader.js" defer></script>
<link rel="manifest" url="dmxConnect/api/FrontEnd/manifest.php">

i even moved the is=“dmx-app” to the top
<html is="dmx-app" id="as">

but not working…

but thanks for you help and your insight into this issue i have … i have even tried php json encode… but all failed… ill have to search more maybe JavaScript elements id as a value…

Sorry to hear it didn’t work - I’m not familiar with manifest.json, but as the Server Action concerns I believe you did everything right :slight_smile:

Perhaps now you’re battling another issue

But thank you for your insight… it was a very good plan… and at least we tried… almost pulled it off … im sure of that…

1 Like

… something very very simple with php… if you can pass a var to a page, then why not!!!
so i have gone back to this route… of php and encode json. And just passed the a few variables via the url… sometimes i overthink these stupid things…

<link rel="manifest" href="manifest.php?manifestmainname=<?php echo $company_name; ?>&manifestshortname=<?php echo $company_name; ?>">

Anyway thanks @Apple for your help. but it seems i just had to approach it differently