Render specific field collection fields in twig template - drupal

I have a field collection named, "field_client_scroll" which has multiple fields, two text and an entity reference field to a media image named "field_thumbnail_client". For the text fields I can print their value using
{{ item.content['#field_collection_item'].field_title_client.value }}
I tried to use the following, but with no results
{{ item.content['#field_collection_item'].field_thumbnail_client.value }}
I would like to know what I need to use to print the image or the url to the image using the field collection field.

Related

Change Color Using Metafields

I want to try and change Specific just so I can customize my dawn store more
enter image description here I am not exactly sure where that is
I tried changing product-variant.liquid but to no avail I thought it would change but it didnt I am not sure why I cant get it to work on my shopify store
Follow the below instruction :
Add a metafield to the product variant using the Shopify admin. You
can do this by navigating to the product variant, scrolling down to
the "Metafields" section, and clicking "Add a metafield".
In the "Namespace" field, enter a unique identifier for the
metafield. For example, "my-shop-color".
In the "Key" field, enter a key for the metafield. For example,
"color".
In the "Value" field, enter the color value you want to use. For
example, "#FF0000" for red.
Save the metafield.
In your product-variant.liquid file, you can use the following code
to retrieve the value of the metafield:
{% assign color = variant.metafields.my-shop-color.color %}
You can then use the color variable to set the background color or any other styling for the variant. For example:
<div style="background-color: {{ color }};">
{{ variant.title }}
</div>
I hope this will help you.

Access custom property in stencil html template

I've created a new custom property for a product and I need to access it in the HTML template.
I can see that these are held under product.custom_fields, but how do you reference a key and value of a specific custom property?
For example, I have a custom field with key of 'note' and value of 'one'.
I've tried displaying 'note' and 'one' on the HTML template the following way:
{{ product.custom_fields.note[key] }}
I'm however getting 500 errors. I haven't found a reference that would explain how to do this.
I just found a much cleaner solution for accessing a custom field by name:
{{#filter custom_fields 'your-custom-property-name' property='name' }}
{{value}}
{{else}}
a fallback string in case you don't have it
{{/filter}}
This is an undocumented feature of the filter helper from handlebars-helpers repo. It allows you to filter on a specific property.
Try this
{{#each product.custom_fields}}
{{#if name '==' 'note'}}
{{name}}: {{value}}
{{/if}}
{{/each}}

Remove item from associative array using twig template engine

I'd like to remove an item form associative array within twig page.
Knowing that I have already the key of the item such as "key1"

How to render only one field of a form with symfony

I want to render only one field of a form. When i put {{form_end(form)}} every other field are coming (symfony doc show it clearly) but how to render only one field ? If i dont put {{form_end(form)}}, there is only one field, but no save button
thanks
Yes, CSS can do the trick. But do you want the working of your application to depend on client side styling rules? In most cases it might beter not to render the field HTML at all.
There are two ways in which you can fix this in your template.
Put {% do form.field_you_want_to_hide.setRendered %} before your {{form_end(form)}}.
This will mark the field as rendered and thus it will not show up when form_rest is called.
Instead of {{form_end(form)}}, use {{ form_end(form, {'render_rest': false}) }}, as explained in the Symfony Twig documentation.
It would be even better to change your form class such that the fields are removed from your form. Is it your own form you would like to render, or a form from a third party bundle?

collective.listingviews:how to use custom fields to display dexterity based image field and richtext field

I'd like to use the collective.listingviews controlpanel to display an image and richtext field. I have the image field working but would like to know if there is a simpler way to retrieve the image. When I try to retrieve the richtext field I end up with a permissions error.
The details:
I have a custom dexterity content type (examplecontent) and a collection which retrieves these examplecontent types.
To display the content types I've created a custom 'listingview' for the collection, the goal is that for each retrieved item the following should be displayed:
A RichText Field named 'body'
An Image Field named 'screenshot'
This is a mockup of how the layout might behave:
To retrieve the image field I'm using the custom tal expression:
python:"<img src='%s/view/++widget++form.widgets.screenshot/##download' />" % item.getObject().absolute_url()
To retrieve the body field I'm using the custom tal expression:
python:item.getObject().body
The image field is working but the richtext field gives the following:
RichTextValue object. (Did you mean .raw or .output?)
When I change the tal expression for the richtext field to the following:
python:item.getObject().body.output
I then get the following permissions error:
Insufficient Privileges
You do not have sufficient privileges to view this page. If you believe you are receiving this message in error, contact the site administration.
First off, you should change
python:"<img src='%s/view/++widget++form.widgets.screenshot/##download' />" % item.getObject().absolute_url()
to:
python:"<img src='%s/view/++widget++form.widgets.screenshot/##download' />" % item.getURL()
Since this way means you don't have to get the full object. Note the use of the getURL() method.
For the second expression, try something like this:
item/getObject/##text-transform/body
or
python: item.getObject().restrictedTraverse('##text-transform/body')
untested

Resources