Product Detail Dropdown (That shows Product title, image and price) inside a contact form in shopify - forms

I am trying to add a select dropdown (That shows Product title, image and price) form field inside a contact form that enable user to select product and selected products show under the field.
I am using this code but it only display 50 product and just showing product titles and product image path, not the actual image.
` Products
Choose your product
Others - No product-related concerns
{% for product in collections['all'].products %}
{{ product.title}}{{ product.featured_image}}
{% endfor %}
</select>`
enter image description here
This is the output.

Related

How to show the category name on the category listing page?

I've been using Wagtail for a while, for my basic website, but during the pandemic I've had to create online versions of all my courses -- I teach at a university -- and I've decided to do this in Wagtail. It's a much more robust solution than anything the university can provide. (I think a lot of people are in my situation.) It's been great so far, but I'm not a programmer (I teach Creative Writing!) and so I'm a bit out of my depth with a few things. Here's one thing I could use help with. I have categories (as per Kalob's tutorials), and I have category listing pages. I click on a category and I get a page showing just pages in that category. So far so good. But how would I show, on these listing pages, a header that says "Showing Pages in Category X"? Here's what I have in the models for my courses app (taken straight from Kalob's tutorial on categories):
#route(r"^category/(?P<cat_slug>[-\w]*)/$", name="category_view")
def category_view(self, request, cat_slug):
"""Find courses based on a category."""
context = self.get_context(request)
try:
# Look for the course category by its slug.
category = CourseCategory.objects.get(slug=cat_slug)
except Exception:
category = None
if category is None:
# This is an additional check.
pass
context["courses"] = (
CoursePage.objects.live().public().filter(
categories__in=[category])
)
And here's what I have in the template for these category pages:
<ul class="menu-list">
{% for cat in categories %}
<li>
<a href="{% routablepageurl page "category_view" cat.slug %}">
{{ cat.name }}
</a>
</li>
{% endfor %}
</ul>
As Intended, the above shows all categories. How would I show only the category of the selected pages, so that I could put that in the title of the page? I've tried a few things, but as I said, I'm out of my depth here and I am just guessing and googling -- so far, without success. I know a lot of the ways to not make this work.
Not sure if I am missing something, but if you want to make the current category available to your template (the one based on the slug in the URL). You can add it to the context to make it available in your template, similar to how you are adding courses.
Example
my_model.py
#route(r"^category/(?P<cat_slug>[-\w]*)/$", name="category_view")
def category_view(self, request, cat_slug):
"""Find courses based on a category."""
# ... rest of the code from above
context["courses"] = (
CoursePage.objects.live().public().filter(
categories__in=[category])
)
context["current_category"] = category
my_template.html
<h2>{{ page.title }} - {{ current_category }}

Symfony2 How to create specific collection widget for specific colletion in deep collection form nesting

I have little more complex problem, i have never done more than 1 nested form in an a form, which was fine to just include a custom collection widget template. (Reason: I need to re-code website based on laravel and Spaghetti code, with Spaghetti structure with tons of bugs and buggy patches, what i am fixing for a year now, and i have decided to recreate this app on my loved Symfony).
Let me write the structure:
Questionnaire (short name QN for later use)
- QN -
|_ QN Sections -
|_ QN Parts -
|_ QN Groups -
|_ QN Questions -
|_ some predefined answers
As you can see each QN can have Sections, these sections can have parts, these parts can have groups, and these groups can have questions, these questions have some conditional fields like if question type is "A,B,C" it has another nested collection form for these predefined answers,...
Problem is that for each of these collection form, i need to specify somehow a custom collection wiget template, because each of these collection form has different layout of fields, how they are displayed and handled.
Currently i have created a collection widget template that i include before QN Sections to style QN Sections, but this template is used also for his child collection form, what i need to avoid.
In a perfect world it should work like "prototype_template" => "some path", and then create javascript for each tempalte to add, remove, etc.
Here is an screenshot with some information how it looks now:
In final stage using these separate templates for each collection form, the "form builder" should look like actual web app.
If you need more informations please let me know, i will provide as much informations as i can.
To recap: I need somehow to specify for each nested collection form type to use different collection form widget template.
Thank you
Finnaly I got it.
The main collection template i have used was collection_widget block.
That was bad because it was too general. I hav renamed it to _questionnaire_questionnaireSections_widget, so the 1. level collection were themed. But after day of headake, 1000 combinations of form names i have got how to name the 2. level collection, its block name is "_questionnaire_questionnaireSections_entry_questionnaireParts_widget" what simply stand for "_mainFormTypeName_fieldNameOfFirstCLevelCollection_entry_FieldNameOfSecondLevelCollection_widget"
Than i just needed to place each template file to right place at the right moment.
edit.html.twig
{{ form_start(form) }}
{% form_theme form "::templates/collection/questionnaire/questionnaireSection.html.twig" %}
.........
{{ form_widget(form.questionnaireSections) }}
questionnaireSection.html.twig
{% block _questionnaire_questionnaireSections_widget %}
.............
{% for rows in form %}
{% form_theme form "::templates/collection/questionnaire/questionnairePart.html.twig" %}
questionnairePart.html.twig
{% block _questionnaire_questionnaireSections_entry_questionnaireParts_widget %}
So problem is solved, i have successfully themed nested collections. Thanks to myself and to symfony docs that has 0 words documentation to nested form theming, but they has some information about the "entry " part.

Simple forms post field specific field values

I am using simpleforms as a subscription form for subscribing to classes. The form uses a use_as and also sends the email to the sender as a confirmation.
I have edited the email twig template and added further informatie about what the subscriber should do next.
My question is if it is possible to set a specific field value in the instruction text. So far I have not yet been able to do this correctly. I would like to only show the field "name:" in this instruction text so that every sender that gets this email is greeted with his own name.
The for loop that is used in the email template is
{% for value in form %} {{ value }} {% endfor %}
And i'm looking for a specific field to be set instead of all the values of the form.
You can directly access the fields in your emailtemplate, you don't need to use a loop for it.
So if you have a field called 'name' in your config file you can use {{ form.name }} in the email template to display the value that the visitor has entered directly.

Symfony2: form error displaying

I need to validate field in a Symfony2 form. It's OK, but the error is always displayed next to the related fields.
In case of any error, I also would like to display a message at the form of the form which would say 'Carreful, one or more fields are not valid, please look below'.
Is it possible ? Should I use a custom constraint to add a violation ?
Supposing your form name is form, you can do the following in your view (twig)
{% if not form.vars.valid %}
Carreful, one or more fields are not valid, please look below
{% endif %}

Symfony2 Custom form field for hierarchy in select element

I created a custom form field extending de entity field for display a select with hierarchy of destinations. Table destination is a nested tree based on gedmo Nested Tree behavior. It's works fine but i need to show the hierarchy in select options based on tree level. For example:
Destination1
--Subdestination
--Subdestination
Destination2
--Subdestination
--Subdestination
----Subdestination
I build the tree correctly in custom form field class but i dont know how render properly the options for this select type. I was thinking via form theming override the block {% block choice_widget_options %} but this affect all selects.
How can i do that or there are a best way to do it?
you could try to implement __toString() function on your entity so ti displays proper number of "---" before label
check vendor\symfony\symfony\src\Symfony\Bridge\Twig\Resources\views\Form\form_div_layout.html.twig to see how it workds and override the {% block choice_widget_expanded %} block or whichever type of list you use, you need to add {% form_theme form _self %} in the .twig file where your form is so the twig will search for overriden blocks in the same file