django-haystack and endless pagination can't {% include page_template %} - django-haystack

#page_template('voziladijelovi_dodatak.html')
def traziVozilaDijelovi(request):
sqs = SearchQuerySet().filter(kategorije=('Vozila i Dijelovi')).facet('podkategorije').facet('drzava').facet('grad')
view = FacetedSearchView(form_class=FacetedSearchForm, searchqueryset=sqs)
return view(request)
in template {% include page_template %} doesn't work.
extra_context {u'page_template': u'voziladijelovi_dodatak.html'} is missing from
create_response()
How to include this in view

Do you mean like:
view = FacetedSearchView(form_class=FacetedSearchForm,
searchqueryset=sqs,
template='voziladijelovi_dodatak.html')

Related

How to add entity extension in Shopware 6 App?

I want to query the categories of the product in the product listing of a Shopware app, so that I can query the customFields of all categories. Is this even possible with an app?
I have already tried via a navigation-page-loaded. And when I override the box-standard.html.twig and access the product, I can't access the categories there.
For each product i want the categories extensions
As the categories association is not loaded for products in the listing you have to fetch the categories using an app script.
As already noted, add the script to the navigation-page-loaded hook, i.e. in Resources/scripts/navigation-page-loaded/category-loader.twig:
{% set products = [] %}
{% if hook.page.cmsPage.type === 'product_list' %}
{% foreach hook.page.cmsPage.sections as section %}
{% foreach section.blocks as sectionBlock %}
{% if sectionBlock.type !== 'product-listing' %}
{% continue %}
{% endif %}
{% foreach sectionBlock.slots as slot %}
{% if slot.type !== 'product-listing' %}
{% continue %}
{% endif %}
{% foreach slot.data.listing.entities as product %}
{% set products = products|merge([product]) %}
{% endforeach %}
{% endforeach %}
{% endforeach %}
{% endforeach %}
{% endif %}
{% set categoryIds = products|reduce((carry, v) => carry|merge(v.categoryIds), []) %}
{% if categoryIds %}
{% set categories = services.repository.search('category', {'ids': categoryIds}) %}
{% foreach products as product %}
{% do product.addArrayExtension('myCategories', {
'categories': categories.entities.getList(product.categoryIds),
}) %}
{% endforeach %}
{% endif %}
Where we first extract all the products, than load the categories of all products at once, and than assign the categories back to the products.
Note that for reading the category entity you need the correct permission, i.e. in the manifest.xml add:
<permissions>
<read>category</read>
<read>category_translation</read>
</permissions>
Now you should be able to access in the box-standard.html.twig template the categories using product.extensions.myCategories.categories.
If I understand your issue correctly, you are trying to access a product's category's custom fields in some piece of storefront logic (like a Twig template).
The way I see it, you would have to add a script that would enable you to query the repository for the categories and their custom fields. The issue is, a SalesChannelProductEntity will not contain the information about all its categories (only the SeoCategory), so you might need to first query the product_category repository.
Generally, it is going to be complicated but it should be doable.

How to add active class if current url matches the given (twig)

I want to write manually a side menu for the store on opencart, and I have a problem - how to make twig add the class "active" to the link for current page
I tried to do it like this
page about something
but it doesnt work
This is exactly what the category module does so you can copy it:
{% if child.category_id == child_id %}
- {{ child.name }}
{% else %}
- {{ child.name }}
{% endif %}
You can find the file above here:
/catalog/view/theme/default/template/extension/module/category.twig
You can find its controller here:
/catalog/controller/extension/module/category.php
They way I would do it is out the route request in by the controller phone file. This would be something like the below:
$urlroute = $this->request->get['route'];
Then in the twig file you could simply check the route variable in an IF query
{% if urlroute == "something" % }
page about something
{% else %}
page about something
{% endif %}

OctoberCMS Partials sharing variables life cycle

I'm new in October CMS and I try to develop some components and these components have more than one page. I include every page as a partial in the default.htm file with an if condition depends on the type property of the page.
{% set type = __SELF__.property('type') %}
{% if type == 'y' %}
{% partial 'x::yy' %}
{% elseif type == 'x' %}
{% partial 'x::xx' %}
the problem is when I have a collection of items in one page and send id of one of the items to another ajax handler and want to retrieve full info of the item, I can't pass it to next page because of the page cycle in October CMS.for example :
// firstpage
{% set posts = __SELF__.posts %}
{%for post in posts%}
<button data-request="handlerX" data-request-data="id: {{post.id}}">
{%endfor%}
//hanlerX
public function onHanldlerX(){
$post = $this->post = POST::where('id',post("id"))->first();
return redirect()->to('/my-posts/'.$post->slug);
}
//nextpage -> my-posts/$post->slug
// post informations is unavailible
what's the best way for these type of components?
Is It the right way for this?
how can I send variables to view after the OnRun method in components?

How can I set selected SelectField value in Jinja

I'm working on a project using Flask and flask-wtforms, and I'm facing a problem setting selected value for Selectfield in Jinja: I tried the following but nothing worked...
#app.route('/route', methods = ['GET','POST']
def route():
form = InputForm(request.form)
# Data base connection code returns connection as con and cursor as cur.
cur.execute('SELECT field FROM Table WHERE Row = %s', (Rowvar,))
Data = cur.fetchall()
con.close()
return render_template('template.html', form = form, Data = Data)
the HTMLtemplates I tried:
Try1:
<html>
...
{% for i in Data %}
{{form.selectfield.default = i[0]}}
{% endfor %}
...
</html>
Try 2:
<html>
...
{% for i in Data %}
{% form.selectfield(default = i[0]) %}
{% endfor %}
...
</html>
Try 3 using render_field function:
<html>
...
{% for i in Data %}
{{render_field(form.selectfield, default = i[0])}}
{% endfor %}
...
</html>
I also tried using render field with (value) and (select) instead of default and none of them actually worked.
So.. can you please help me on how to set a SelectField value using Jinja the right way.
Thank you very much.

IF URL statment opencart 3 twig files

can you see whats wrong with this :
{% if 'information_id=10' in url %}
Im trying to use an if statement when the url contains that string, but its not working, have i done something wrong?
Many thanks!
If you want to do something in a special information page, edit catalog\controller\information\information.php, find:
if ($information_info) {
Add after it:
if ($information_id == 10) {
$data['target_page'] = true;
} else {
$data['target_page'] = false;
}
Now in catalog\view\theme\your-theme\template\information\information.twig file, use it:
{% if target_page %}
This is target page.
{% endif %}
You may need to refresh modifications and clear theme cache.
Edit:
or you can pass $information_id from controller:
$data['information_id'] = $information_id;
And in view file:
{% if information_id == 10 %}
...
{% endif %}

Resources