Access label from config.json select in Publii template
- This topic has 4 replies, 2 voices, and was last updated 4 months, 3 weeks ago by .
- AuthorPosts
- October 4, 2020 at 9:11 pm#3959
btrem
I’m developing a sub-theme with an address state/province selector in the config.json:
{ "name": "state", "label": "State", "group": "Contact", "type": "select", "options": [ { "label": "Alabama", "value": "AL" }, { "label": "Alaska", "value": "AK" } ] }
In my template, the state is in an `` element:
<abbr>{{@config.custom.state.stateName}}</abbr>
Is there a way to access the `label` from the json file? If so I could do something like this:
<abbr title="{{@config.custom.state.stateNameLabel}}">{{@config.custom.state.stateName}}</abbr>
with the result:
<abbr title="Alabama">AL</abbr>
Or, is there another way to send both an abbreviation and full name to the template? I was thinking something like:
{ "name": "state", "label": "State/territory", "group": "Contact info", "type": "select", "options": [ { "label": "Alabama", "value": [ "AL", "Alabama" ] }, { "label": "Alaska", "value": [ "AK", "Alaska" ] } ] }
But there’s no way to access the value. Using <code class=”EnlighterJSRAW” data-enlighter-language=”generic”>@config.custom.state.stateName produces no output, while <code class=”EnlighterJSRAW” data-enlighter-language=”generic”>@config.custom.state.stateName.value[0] produces an error.
Meta: I’m putting this in General Inquiry, maybe it belongs in Feature Suggestions? (Or maybe in the bit bucket!)
October 5, 2020 at 5:10 am#3962Bob
SupportYour field name is “state” not “stateName”, so the @config variable should contain “state“, and finally looks like this:
<abbr>{{@config.custom.state}}</abbr>
The “title” attribute phrases should be placed in the language file.
--
Do you appreciate the support you've received today? If so, consider donating to the Publii team by clicking here; we'll be sure to use your donation to make Publii even better!October 5, 2020 at 9:51 pm#3975btrem
Your field name is “state” not “stateName”, so the @config variable should contain “state“
That was a typo. In my template, I’m using “state”, and it’s working fine. The question is can I get the label of the drop down from config.json.
In addition to my typo, I think I didn’t explain my question clearly. I now see that the forum software kind of garbled my original post. (It appears to really muck things up with inline code. Has anyone else had problems with that?)
<abbr>{{@config.custom.state}}</abbr> The “title” attribute phrases should be placed in the language file.
I don’t understand this. Might be because of the problems I had writing the original post. What language file are you referring to?
October 6, 2020 at 5:12 am#3976Bob
SupportHI,
This one https://getpublii.com/dev/translations-api/
--
Do you appreciate the support you've received today? If so, consider donating to the Publii team by clicking here; we'll be sure to use your donation to make Publii even better!October 10, 2020 at 4:34 pm#4038btrem
Ok, so I create theme.lang.json with this:
{ "states": { "AL": "Alabama", "AK": "Alaska", "AZ": "Arizona", "WY": "Wyoming" } }
So my theme has a drop down where the user selects a state, say “Alabama” (see the original post in this thread), and the template puts in “AL”. Now, what handlebars expression do I use to get “Alabama”?
- AuthorPosts
- You must be logged in to reply to this topic.