Replacing image url prefix using a variable

HI,
looking at this video Headless Strapi Integration - Divhunt No-Code Web Builder - YouTube
I’m also using Strapi, but will change the strapi I’m using in dev to one in prod, hence the image prefix will change.
Thus I want to have a single place (a variable or function) where I’ll setup the value in the prefix. I’ll call it instead of the Replace function used in the video example.

How can I add & use this function or variable?

Hi @xmasrock

I’ve added variable for strapi ($strapi) as object, for now it contains the endpoint. To access endpoint > ${strapi->get(‘endpoint’)}

1 Like

@xmasrock

Also to mention, there’s 2 ways to access variables

If you are only displaying the value of variable, you can use following:

$strapi->get('endpoint')

But if you want to connect 2 values inside same input field then use {}

${strapi->get('endpoint')} - some text here if neede - ${blog->get('image')}

1 Like

@dejan : when trying to use ${ … } in the UI, I can’t add the last “}”
image

@xmasrock

Sadly we don’t have UI that can combine 2 variables yet into single input field.
What you can do is use UI to get both values and then wrap both values in brackets {}

For example if you have used UI to get $strapi->get(‘endpoint’) then wrap it manually to ${strapi->get(‘endpoint’)}

Then do the same for URL and merge both strings into text input field.

Could you share your domain name and I can help you do that?

My domain is “temlab”

@xmasrock

Most often request fail to execute on http://noelweb.hd.free.fr:52337/api/societe
image

Is there any type of limit on your end?

I’m suspecting free.fr to have put a limit on their “free” domain names. I’ll try to change it with the IP address

@xmasrock

We are not allowing IP address as URL.
Give us some time to investigate why is this happening. It may be our servers limit.

Thanks for patience.

Also regarding UI for variables, we will be updating with new and improved UI soon.

I see changes happening from time to time :rofl:

while I’m in the Rest-API screen, it’s a bit strange to have an “update” button on the different sections (PARAMS, HEADER, …) and not on others

@xmasrock

Most of our system is based on auto-save, so we could also add those (params, headers) to be autosave too, would that work for you?

Also seems like domain http://noelweb.hd.free.fr:52337/api/societe is no longer working, I am trying to determine what was issue.

@dejan : I confirm that the data is not retrieved right now.
I’ve tested with Postman and it works well.

@xmasrock

I can’t get that endpoint to work at all. I asked also few people to test it, they all get same error, “could not resolve host”.

Yes that’s because I’m shutting down strapi when I’m not on this project. We need to synchronize for tests :wink:

strapi env running and responding

I’ve put this into a paragraph

${${strapi->get('endpoint','')}${rest.strapisocieteresult->get('data')->get('attributes')->get('logo')->get('data')->get('attributes')->get('url')}}

It’s not working, the first variable is ignored
image

the combined is now working with just :slightly_frowning_face:
${strapi->get('endpoint','')}${rest.strapisocieteresult->get('data')->get('attributes')->get('logo')->get('data')->get('attributes')->get('url')}

URL: http://noelweb.hd.free.fr:52337/uploads/TEM_Lab_logo_5a33e5106b.png
however, when using this on <img src= seems not working:

Looking at the generated site, the prefix is removed: