How to display contact information in footer template Open Cart? - opencart

I use new version of OpenCart 3.
In administrativ part I can set default phone/email data.
Then in footer.twig I tried to display phone number like:
{{ config.get('config_phone') }}

In catalog/controller/common/footer.php
$data['telephone_number'] = $this->config->get('config_telephone');
In catalog/view/theme/default/template/common/footer.twig
{{ telephone_number }}

Related

Django filters - adjusting box width

With django_filters, I have my filterset, everything works fine it's just the display that I am stuck with (box width).
As you can see below, I have changed the "size" attribute of some of the filter options - because the default is too wide. But the "rating" one, which is a NumberInput, doesn't work for some reason. The "size" attribute works for TextInput but not NumberInput.
I want to change the size or rather the width of the NumberInput box that will be displayed in the template (see template pictures below).
Can anyone help? Thanks in advance!
class ReviewFilter(django_filters.FilterSet):
comments = CharFilter(field_name='comments', lookup_expr='icontains', label="Comments ", widget=TextInput(attrs= {'size': 15 } ))
role_title = CharFilter(field_name='role_title', lookup_expr='icontains', label="Role title ", widget=TextInput(attrs={'size': 15 } ))
date_range = DateRangeFilter(field_name="date_created", label=" Posted date ")
**rating = CharFilter(field_name="rating", lookup_expr='gte', label="Minimum rating ", widget=NumberInput(attrs={'size': 1 } ))**
class Meta:
model = Review1
fields = '__all__'
exclude = {'recruiter', 'date_created', 'user'}
I have this:
Screenshot - Look at "Minimum rating" box width
But I want this:
Screenshot with filter search bar - Look at "Minimum rating" box width
I found a solution in the thread below by using the attribute - "style" : 'width6ch'
Apparently NumberInput doesn't have a working "size" attribute in HTML yet.
Solution to my problem
You cannot directly style the django-filters search fields. I was stuck with the same problem and here is my way of solving it.
Step 0 : intall widget_tweaks by pip install django-widget-tweaks
step 1 : add widget_tweaks to INSTALLED_APPS in your settings.py
step 2 : add {% load widget_tweaks %} into your template.html
step 3 : style individual elements in template
<div class="form-group col-sm-4 col-md-3">
{{ filter.form.comments.label_tag }}
{% render_field filter.form.comments class="form-control" %}
</div>
<div class="form-group col-sm-4 col-md-3">
{{ filter.form.role_title.label_tag }}
{% render_field filter.form.role_title class="form-control" %}
</div>
this way you can style individual form elements from filters, you can also add html tag attributes such as type or class and style them based on your needs.
you can use this link for reference. Link for Reference

Opencart 3.0.2.0 and Journal 3 theme customer name in Top Menu

I want to add customer first name on Journal theme top menu module. I am adding {{ text_logged }} in top-menu.twig but it can not get text_logged from controller. How can I get text_logged from catalog/controller/common/header.php?
{% if logged %}
{{ text_logged }}
{% endif %}
$data['text_logged'] = sprintf($this->language->get('text_logged'), $this->url->link('account/account', '', true), $this->customer->getFirstName(), $this->url->link('account/logout', '', true));
I want to see "Hello John Do" on Journal theme top menu $ US Dollar instead
I had contacted the developer regarding the same issue for the journal theme v3. They told me that it can be displayed using this:
Welcome back, {{ $customer_firstname }} {{ $customer_lastname }} !
to show customer firstname and lastname in menu items.
I have integrated that into my code, and it now shows the customer name, when logged in. No need to edit OC MOD
You need to add your code using ocmod or vqmod to the Journal theme common/header.tpl. I highly recommend do not change the Journal's core codes because of ridiculous cache system (even devs couldn't get rid of it). Also here is a solution : You can edit this one for your purpose

Django bootstrapform render field and lable separate in template

I am using Django 2.0.4 with bootstrapform https://github.com/tzangms/django-bootstrap-form . I would like to render my field and label separately in my template.
Currently I can render the field using:
{% load bootstrap %}
{{ form.fieldname|bootstrap }}
I would to find a way to separate the render of the label from the field so that I can insert text next to the label for selecting tool-tip. Is anyone able to point me in the right direction to achieve this? Any help will be much appreciated!
Try the following : This link provides more info
{{ form.field_name }} will render the field
{{ form.field_name.label }} will render the label
{{ form.field_name.id_for_label }} the ID

Querying a single field within a Jinja2 template

I'm working on an application where users can enter work requests, and subsequently go in and search for requests. The issue I'm having is building out the request summary screen. Basically, it lists the results of a search query. The snippet from the template is as such:
{% for req in workrequests %}
{{ req.id }} {{ req.customer }} {{ req.dateEntered }} {{ req.Contact }}
{% endfor %}
Here's wher I get hung up. The req.customer, and req.Contact fields are just keys for the customer and contact databases. I want to display the customer name and contact name. I assume the following queries should do the trick:
Customer.query.filter_by(req.customer).one()
Contact.query.filter_by(req.Contact).one()
Problem is, that will return the entire record. I'm just after the name field from both of those tables to put into my template, which is where the problem is. I'm not sure how to proceed with this
Customer.query is a short form of db.session.query(Customer). Use the latter to query for specific columns:
db.session.query(Customer.name).filter_by(id=req.customer).one()
Although I think that what you really want is a single query that gets all the data at once. Something like:
db.session.query(
WorkRequest.id,
WorkRequest.dateEntered,
Customer.name,
Contact.name
).join(
Customer,
Contact
).filter(...)

How to get form fields' id in Django

Is there any way to get the id of a field in a template?
In the HTML I get: <input name="field_name" id="id_field_name"...
I know I can get the name with {{ field.html_name }}, but is there anything similar for getting the id?
Or can I only get it like this: id_{{ field.html_name }}?
You can get the ID like this:
{{ field.auto_id }}
You can also use id_for_label:
{{ field.id_for_label }}
This doesn't work for every form field.
For instance {{ form.address.auto_id }} works while {{ form.address.auto_name }} will not.
However you can use {{ form.address.html_name }} to get the equivalent answer.
Here are the docs
From the documentation-
each form field has an ID attribute set to id_<field-name>
, which is referenced by the accompanying label tag. This is important in ensuring that forms are accessible to assistive technology such as screen reader software. You can also customize the way in which labels and ids are generated.
So I would like to say id_field-name , you collect the field name from the model.
Here is the link to the documentation
In Django 2 you can retrieve the ID for a specific field using {{ field.id_for_label }}
This is documented here.