Can you use code in archetypes?

For example, in the theme I am creating, I want to populate certain archetype default values based upon stuff from config.toml.

Can I use these in archetypes?


According to my random little test, no you cannot.

I have tried this:

website = {{ $.Site.Params.homepage }} and that returns the error:

RROR: 2016/09/25 04:46:16 content.go:61: Error processing archetype file /Users/mattstratton/src/castanet/exampleSite/themes/castanet/archetypes/ Near line 19 (last key parsed 'website'): Expected value but found '{' instead.
   "Invalid",                                                                                                                                                                                                                                       │Error: Near line 19 (last key parsed 'website'): Expected value but found '{' instead.```

If I try 
`website = '{{ $.Site.Params.homepage }}'`

the result in my frontmatter is
 `website = "{{ $.Site.Params.homepage }}"`

I've tried both single and double quotes, and also with and without the `$` in front :slightly_smiling:

What stupid mistake am I making?

What you are trying to do isn’t possible (although the parsing shouldn’t have thrown that error, that is a bug). I answered too fast and without thinking.

The current only way to use anything from the site config in an archetype file is in the content section of the archetype file, via shortcodes.

Well, I feel better then :slight_smile:

1 Like