I've installed the group module on Drupal 8 :
If I add the code {{ group.id }} in the twig of the group, it doesn't display the ID. How to print the group ID in twig ?
The group ID will be a FieldItemList object and cannot be printed directly. As such, you will need to use {{ group.id.value }}. Similar to this answer.
The fact that you did not report a Twig error, suggests to me that the change was not reflected on the frontend website. Try clearing your cache. You may want to read Debugging Twig Templates.
Related
I've been searching the internet for hours but I just can't seem to var_dump within the invoice template. I need to put things like EAN etc. in the invoice template but only for certain customer groups, that's why I need to know the variable names.
In Shopware 5 it was var_dump plain and easy but in Shopware 6 nothing I try seems to work.
I've already tried {{ dump() }} within twig code blocks but nothing happens.
Help would be greatly appreciated!
In general {{ dump() }} should work inside document templates, but the dump command is optimized for html output and not pdf output.
Please ensure that you set APP_ENV = "dev" or APP_DEBUG = 1 inside your .env file, because otherwise the twig dump() command is not available.
Also ensure that you call the dump from a block that is rendered in the output of the document (so everything inside the <body> tag).
Additionally simply calling {{ dump() }} inside a document template probably leads to an infinite loading or out of memory errors, because twig tries to dump to much data.
For document templates, the main variable you have access to is the order, which is an OrderEntity. The order entity has a orderCustomer property, so you could use a {{ dump(order.orderCustomer) }} to get the available data of the customer of an order.
To get all available variables in twig use {{ dump(_context) }}.
I am using contentful. In one of the content model, I want to display dynamic value based on the option selected.
e.g. In contentful, I am having message as: Congratulations, your <USER_TYPE> account has created successfully.
I have options as admin/moderator/user then if
I select admin, message should get display as: Congratulations, your admin account has created successfully.
I select moderator, message should get displayed as: Congratulations, your moderator account has created successfully.
How can I replace <USER_TYPE> with the selected values? Please guide.
I got the answer.
In contentful, put the variable as {{ variable_name }} and in the code replace that variable_name with dynamic value as:
import Mustache from 'mustache';
Mustache.render(value, {variable_name: variable_value});
I am using vueJs, so this implementation refers javascript.
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
I'm currently working on creating a custom display template for people search result page. I copied out of the box Item_Person.html search display template and modified it to display some more fields.
In the out of the box template also there is a managed property called skills but when I using it, its not returning any values associated with the user profile skills property (SPS-Skills).
As you can see its already mapped but Skill value always comes as empty. I want to retrieve and display inside the custom template.
Please help me if you have done something similar.
Check the following steps
Add meta data to ManagedPropertyMapping
2.Then inside the fuction get the value of metadata
<!--#_ var datacreated = $getItemValue(ctx, "Created");_#-->
3.Then palce the variable where you want <h2> _#= datacreated =#_ </h2>
Thats it publish the html hope its work
Is there a way to set Expression Engine entries to be viewable by Super Admins but prevent everyone else from seeing it?
Thanks
It depends on how you have things set up.
You can set templates to only be viewable by super admins, so you could handle this at that level.
Or in the channel entries tag itself, you could set the status parameter depending on whether someone is a super admin and then use a certain status for the restricted entries (which could be closed if you like, or a custom status). Or you could do the same thing with categories instead if you prefer.
The following conditional is true for super admins (more info at http://expressionengine.com/user_guide/templates/globals/conditionals.html#cond_group_id)
{if group_id == '1'}
Using conditions within a channel entries tag can be a bit iffy - it depends on parse order - something like this could work:
{exp:channel:entries status='open{if group_id == "1"}|restricted{/if}' ....}
You can also just output certain stuff within a channel entries loop if the viewer is a super admin, but you need to use {if member_group == '1'} inside the loop instead.
This doesn't work for me, I've found that I can use the dynamic parameters feature of the channel:entries tag pair though to achieve the desired result:
http://expressionengine.com/user_guide/modules/channel/dynamic_parameters.html
:)