How to var_dump? - shopware

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) }}.

Related

How to place dynamic value in contentful?

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.

How to print the group ID

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.

MODX - Access TV's of resource fetched from a ResourceList and display with getImageList

I'm trying to output template variables from resources input into a MIGX template variable, which references a template variable with an input type of 'Resource List'. Is this possible?
I've got a template variable(TV) in MODX which has an input type of "Resource List", this TV is called 'product_offer'. This resource list has a where clause which states that it can only contain products with a certain template ID.
I then have another TV which has an input type of MIGX. I use this TV to allow one of my resources to select a list of Resources in a template variable. The MIGX TV's form tab JSON is below. This TV is called 'offersList'.
[
{"caption":"Product", "fields": [
{"field":"Product","caption":"Product","inputTV":"product_offer"}
]}
]
In one of my chunks i'm using getImageList (snippet that comes with migx) to display the list of resources that I've input into the 'offers_list'. Code snippet below:
[[getImageList?
&tvname=`offersList`
&tpl=`StoreCategoryTpl-New`
]]
The chunk "StoreCategoryTpl-New" accesses the resources with this specific ID's template variables and displays a number of them. A cut-down snippet of the chunk is below.
<div class="product-container">
<img src="[[+tv.productImage:phpthumbof=`w=150&h=150&zc=1`]]" alt="Thumb of ([[!getResourceField? &id=`[[+product]]` &field=`pagetitle`]])" />
<h3>[[+pagetitle]]</h3>
</div>
Everywhere else in the site I have used this chunk to output the result of a getResources call, getResources of course can output Template Variables.
Can I access the template variables from the resources I've selected in my 'offersList' MIGX TV and output them in the chunk? I can't find any material for this on the forum or through Google searching.
If not, is the only solution to do this with getResources, and perhaps make a new TV which allows the user to enter in multiple Resource ID's as the value, then feed that into the getResources call (to only get those resources)?
I can only guess, but did you try and set the input TV Type like mentioned here?
https://docs.modx.com/extras/revo/migx/migx.backend-usage
I'd try and set the TV type.
Anyway, in the output chunk, you are trying to access the TVs like you would do with pdoTools or getResources before. As you would have to set "includeTVs", I guess it is not the default behaviour to read the TVs values from the database.
Yout Attempt to read them with getResourceField instead should work, also with the tv.productImage.
One last thing: you're using phpthumbof. Try pthumb instead, it is the new version and you can use it just like phpthumbof before.

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 to dynamically arrange elements in twig

Lets think of the situation where you have to print out a set of filters (categories, options, price range, manufacturers etc ...).
The frontend designer may want to arrange these elements in many way (for example price range and manufacturers on the same row while the others are stacked on each other).
My first attempt:
Put each rendered filter in a block, then let the frontend designer to decide how/where to render the blocks in the template
The problem: since the filter set is dynamic, I must be able to set block name dynamically say via a variable but it seems not possible at the moment.
My second attempt:
Thinking along the same line, it may be possible to assign the rendered filter in an associative array then let the frontend designer decides where to print out
The problem: in the php template twig does seem have the render which returns the output that can be assigned, doesn't seem to be the case when using pure twig language.
I think I'll first create a categoryFilter.html.twig, optionsFilter.html.twig, priceRangeFilter.html.twig... each containing a specific filter without a special arrangement.
And I'll write a global filters.html.twig that contains the layout, and {{ include }} all filters at the right place.
In such way, your designer just have to update filters.html.twig to change the layout.

Resources