Skip to content

Props: where a value comes from

A prop is a setting of a component: a heading, a link, a color. Three places can give it a value, and the first one that has a value wins:

  1. The page. What you write where the component is placed: an attribute on the tag, a property set by a script, or a data-props script inside the tag.
  2. The site. A value saved in Taggor for this component on this site.
  3. The component. The default its author declared.

A form component my-form declares a prop heading with the default Contact us. The site saved Talk to sales for it:

Terminal window
npx taggor sites props set my-form heading "Talk to sales" --site SITE_ID
  1. The page has <my-form heading="Ask a question"></my-form>. The visitor sees Ask a question: the page gave a value, and the page wins.
  2. The page has <my-form></my-form>. The visitor sees Talk to sales: the page gave none, so the site's value is used.
  3. The page has <my-form></my-form> and the site saved no value. The visitor sees Contact us: neither gave one, so the component's default is used.

So the same component can say one thing on most pages and another on one page: save the usual value for the site, and write the exception on that page's tag.

<!-- An attribute: the prop's name in kebab-case. -->
<my-form heading="Ask a question" submit-label="Send"></my-form>
<!-- A data-props script: one JSON object, for lists and objects, or for a CMS that strips attributes. -->
<my-form>
<script type="application/json" data-props>
{ "heading": "Ask a question" }
</script>
</my-form>
// A property, from your own script.
document.querySelector("my-form").heading = "Ask a question";

When the same prop is written in more than one of these, the property wins, then the attribute, then the data-props script.

A prop cannot be named like something every HTML element already has (title, id, class, style, hidden, lang and the like): the build refuses it. Use heading, label, productName.

The site: one saved value for both environments

Section titled “The site: one saved value for both environments”

A site keeps one set of saved props for a component, and both of its environments use it: production and staging. There are no saved props per environment. To give staging a different value, write it on the staging page, which wins over the saved one.

Terminal window
npx taggor sites props set COMPONENT PROP VALUE --site SITE_ID

The value is public (it is delivered to the page), so never save a password, a key or personal data. --as number, --as boolean or --as json saves something other than text.

When the two environments run different versions

Section titled “When the two environments run different versions”

Staging often runs a newer version than production. If you save a prop that only the newer version declares, production cannot use it yet. Nothing breaks and nothing is lost: production leaves that prop out and uses the component's default, and starts using the saved value by itself when it runs a version that declares the prop. The CLI says so when you save, and npx taggor sites show SITE_ID lists, for each environment, the saved props it is not using.