I have a normal set of widgets that you generally edit on the page, no problem. However, I have a requirement to edit these widgets in a modal schema area as the component is being animated and things get a bit funky. Setting edit:false does stop the area being edited but all the widgets and pieces inside the area can still be edited? I need to stop this as I can’t really edit in either the modal of the page as I get an error saying " You were unable to take control of the document" in the modal and nothing being saved via contextual edits?
1 Answers
I understand what you mean sometimes you need a little bit more flexibility than calling the values of your widget in an non editable singleton or area in your view.html
I found the solution in creating pieces widgets as described in this tutorial This allows you to call values of your widget wherever you want, without any edit functionality. You can call the same field on different places and one in animated and flies around and all stuff, the other static header for example.
Here you'll find an example how I used an pieces widget and displayed all fields on view.html. I have even added an if condition so without user input die fields won't be loaded in your widget.html.
I think this solution fits the best for your needs.
{% for piece in data.widget._pieces %}
<div class="card horizontal" style="
{%- if piece.backColor-%}
background-color:{{ piece.backColor }}
{% endif %}
">
{%- if piece._image -%}
<div class="card-image hide-on-small-only">
<img width="100%" src="{{ apos.attachments.url(piece._image.attachment, { size: data.options.size or 'full' }) }}">
</div>
{%- endif -%}
<div class="card-stacked">
<div class="card-content" style="
{%- if piece.backColor-%}
background-color:{{ piece.backColor }}
{% endif %}
">
{%- if piece.title -%}
<span class="card-title">
<h5 class="accent-color" style="
{%- if piece.titleColor -%}
color:{{ piece.titleColor }}
{% endif %}
">
{{ piece.title }}
</h5>
</span>
{%- endif -%}
{%- if piece.text -%}
{{ apos.area(piece, 'text', {
edit: false,
widgets: { 'apostrophe-rich-text': { } }
}) }}
{%- endif -%}
</div>
</div>
</div>
{% endfor %}
So broken down to the simplest value this {{ piece.titleColor }} means an simple widget schema like this in your widgets index.js
{
name: 'titleColor',
label: 'Title Color',
type: 'color',
help: 'Remove to set title to Accent Color'
},