Get a peek at our latest innovations at Sanity Product Day on Dec 8th →

How to use template values in templates?

16 replies
Last updated: Apr 15, 2021

I am currently creating a new starter template and want to use template-values for presetting some stuff.There are also urls in my template values. Unfortunately after replacing the values these are shown as encoded string. Is there any trick to solve this?
e.g.

<https://sanity>...
will become:

https:&amp;#x2F;&amp;#x2F;sanity-...
This happens when running:

sanity-template build --template-values template-values-development.json

Apr 14, 2021, 1:22 PM

Hi

user A
Thanks for your reply. I just updated the version of sanity-template. Unfortunately with the same result:

https:&amp;#x2F;&amp;#x2F;sanity...

Apr 15, 2021, 8:44 AM

Hi

user A
I just updated the verison of sanity-template. Unfortunately with the same result:

https:&amp;#x2F;&amp;#x2F;sanity...

Apr 15, 2021, 8:44 AM

Hm, what template field is this and what type of file is it? (json or js/ts)

Apr 15, 2021, 8:45 AM

It's the scully.web.config.ts file

Apr 15, 2021, 8:48 AM

setPluginConfig(SitemapPlugin, {
    urlPrefix: 'https:&amp;#x2F;&amp;#x2F;sanity-....,
    ...
})

Apr 15, 2021, 8:48 AM

Just to double check, if you run

sanity-template --version
and
npx sanity-template --version
you get
2.4.2
from both?

Apr 15, 2021, 8:51 AM

npx sanity-template --version shows 2.4.2sanity-template --version shows 2.4.1

how do I need to update it to have a 2.4.2 for both?

Apr 15, 2021, 8:53 AM

npx sanity-template --version shows 2.4.2sanity-template --version shows 2.4.1

how do I need to update it to have a 2.4.2 for both?

Apr 15, 2021, 8:53 AM

you don't need the global one if you always run

npx sanity-template ...
which is a good habit (in my opinion, at least 🙂)

Apr 15, 2021, 8:55 AM

so you can either remove the global (

npm rm -g sanity-template
) or upgrade it (
npm install -g sanity-template
)

Apr 15, 2021, 8:56 AM

True! This works. Thanks a lot!By the way I get an error in

node_modules\sanity-template\dist\commands\utils\fs.js:67:39
I solved this temporary by just returning an empty array in the resolveIgnores function.
I am running this on a win10 64bit machine inside an nx workspace.
Maybe you can note this as an issue at sanity.
Nevertheless now I get the expected result from template builder.
Thanks a lot!

Apr 15, 2021, 8:59 AM

Glad to hear it worked!

Apr 15, 2021, 9:00 AM

Glad to hear it worked!

Apr 15, 2021, 9:00 AM

If you got time we'd be very thankful if you could report the fs issue (preferably with a full stack trace) on https://github.com/sanity-io/sanity-template/issues

Apr 15, 2021, 9:01 AM

alright, I created an issue. Hopefully there's enough information in it.Again thanks a lot for your support

Apr 15, 2021, 9:09 AM

Thanks a lot to you too!

Apr 15, 2021, 9:50 AM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Free to get started, and pay-as-you-go on all plans. Find out more.