Drupal 8 - Display one image from multifield based on the title attribute - twig

I'm working on a Drupal 8 project and having issues trying to access one particular image of an image multifield, eg {{field_images}}.
I have a View with Exposed Filters which returns a list of nodes based on selected taxonomy terms. One of those taxonomy terms, has values that may match the title field of images contained within field_images.
The view displays a teaser list of content based on the filters, which then links to the full node content page.
Normally, the node list returned in the view will only display the first image from the multifield, displayed in the template like this {{ content.field_images.0}} or by simply limiting the images returned in the view itself.
However, in the case that an exposed filter value in the view, say "bathroom" is selected, I want to be able to find an image from field_images that has "bathroom" in the title and display that instead.
Is there any way using either twig logic or views that I can achieve this?
Thanks so much for any assistance anyone may have!

Related

Drupal 8 - how to customise search result template

I have a custom content type with several fields like Price, Product Summary, Product image etc. Is there any way I can access these fields separately on search result page?
I printed the rendered array on mytheme/item-list.html.twig using kint(item.value) which shows that I can only access title, url and type separately like {{ item.value['#result'].url }}, {{ item.value['#result'].title }}. But don't see variables like product_image, product_summary etc. in rendered array.
According to Twig template suggestion the template I need to override is search-result.html.twig. So I copied /core/themes/stable/templates/content/search-result.html.twig to my theme's folder. However, the {{ snippet }} variable does not have information I want to access.
I went through the following steps to customise the result output:
Went to /admin/structure/types/manage/product/display (Structure > Content Types > Product > Manage Display). Turned on Search Index and Search result highlight input.
Navigated to Search result highlight input tab and added (enabled) two fields Product summary and Product price
Went back to search result but I still cannot see the those variables in rendered array.
Can somebody please tell me the best way to accomplish the above?
#Subrata Sarkar There is one option. Firstly,install two module search_api and search_api_page module from drupal.org
https://www.drupal.org/project/search_api
https://www.drupal.org/project/search_api_page
Add server and index in search api.
Add the fields which you want to display on page within index and after all configuration indexed all your data.
After this create and configure search page.And choose view mode option and select a view mode ex: Search result highlighting input or Search index etc.
Hope you get your desired result on search page.For more information,
https://www.youtube.com/watch?v=dNilEVQu94I

how do i add ext.net dynamical web form control and retrieve its contain value to save in DB.?

i want to dynamically add two text box and obtain values from those and display as message ...
please help me though example to demonstrate this scenario where I can learn and apply for my actual problem
Take alook at those examples
http://examples.ext.net/#/XRender/Basic/Add_Items/
http://examples.ext.net/#/XRender/Basic/New_Window/
*those links ,official web site of ext.net.
instead of adding tab or windows ,just change them to TextField.
u can assign unique id for each element added dynamically,and reach those element via Id

Get listitems from Current Site

I am trying to create a Page Layout, that should have a lookup field. Lookup field should always get populated with a list's items.
This list will exist in all subsites, so whereever I create this page, list should get populated with listitems from current site.
I tried using site column lookup field, but it always point to list under top site and not the current site.
Any suggestion on how to make it work or better alternative? Thanks!
Let me know if I can provide more info.
The most straightforward solution I can think of is using a cross site lookup column and creating a seperate fields for each subsite. However, you will need to create and use different Page Layouts for each subsite.
You can use http://sp2010filteredlookup.codeplex.com/ for cross site lookups.
Solution 1 - Use http://sp2010filteredlookup.codeplex.com/
Use filtered lookup solution. So let's say you have your custom Page Layout and custom Page Content Type.
Every time you create new subsite, you should remember go to Pages list settings and edit Page Content Type by adding cross site lookup (with the same field "internal name").
So you still have one Page Layout (and one Content Type). But for each Pages library instance, Content Type contains diff fields (but with the same Internal Name). It will allow you run CAML queries and other things needed without any problems.
Solution 2 - develop custom sharepoint field type.
In edit mode, control will render "dropdown list" and populate data from list instance that is on current subsite. In the field settings you can have relative list url.
Solution 3 - hidden text field / js snippet solution
Page Content Type can contain hidden text field (it can contains selected field value in json format for example). Develop js snippet that will handle all the logic (rendering in edit/view mode, saving etc) and put it on Page Layout (aspx).
I would suggest to use solution #1 or #2.

how to get selected item index in form in j2me

I am appending 20 images in form by using loop.when i am scrolling these images up and down i want selected image index so that i can view bigger size of selected image.
i used this form.append(image)
is there any method or way to get selected item index in form like in list there is getSelectedIndex.
plz help me and provide me gud solution ..
The APIs for javax.microedition.lcdui.Form don't provide a means to get the selected item index, most likely because it wasn't designed for that kind of use. For the use case as described in your question, the correct approach would be to use javax.microedition.lcdui.List. In addition to determining the selected item, List also provides other useful APIs such as setting a select screen command for the items in the list.

Sharepoint: Image field with a link

I would like to add a field to a list with displays an Image, but acts as a hyperlink. In other words like the "Hyperlink or Picture" column, but "Hyperlink AND Picture" instead.
Where the two fields you input would be the URL to the image to display, and the URL of the hyperlink.
This must be possible. I notice that the Type (in a document library) column does just that, and also includes the views that are currently being used (in the case of a folder).
Is it possible to duplicate the computed Type field in a document library to read two other fields in the list (which will act as the image url, and the redirect link)? What would the CAML be?
Thanks in advance if anyone could offer any insight.
Arnhem
This can be done but you would need to develop a custom field type. As you have found, SharePoint's default rendering for pictures is without the hyperlink. You need to change how the rendering behaves in Display mode in your own custom field. Check Patterns in Custom Field Rendering for more info.
There are also several examples of creating custom field types on the web. The MSDN articles give a lot of detail about how it all works but don't let that put you off as it's not too tricky.

Resources