Zoomed in Image in Wagtail - wagtail

I am trying to display a picture using Wagtail but always end up having it zoomed. I tried following the latest documentation and use fill in association with crop. Nothing works:
The component :
{% load wagtailimages_tags %}
/// the challenging part, I tried all kind of dimensions, with or without c
{% image value.illustration fill-300x600-c100 as cover %}
<div class="grid grid-cols-1 sm:grid-cols-2" {% if value.bg_color %}style='background:{{ value.bg_color }} !important;'{% endif %}>
<div class="text-center py-20 px-4 inline-block bg-center
{% if value.position != '0' %}
sm:hidden
{% endif %}
"
style='background-image:url("{{ cover.url }}");'>
</div>
<div class='text-center py-20 px-6 sm:px-12 md:px-12 lg:px-18 xl=px-24'>
{% if value.over_title %}
<h2 class="text-base font-semibold text-redfuf-900 tracking-wide uppercase" >
{{ value.over_title }}
</h2>
{% endif %}
<p class="mt-1 text-xl font-extrabold text-gray-900 pb-6 sm:text-xl sm:tracking-tight lg:text-2xl"
{% if value.text_color %}style='color:{{ value.text_color }} !important;'{% endif %}>
{{ value.title }}
</p>
{% if value.caption %}
<div class="max-w-7xl mx-auto pb-6 px-4 text-justify sm:pb-12 px-0 lg:px-8">
{{ value.caption }}
</div>
{% endif %}
{% if value.CAT_link or value.snippet_cta %}
<a {% if value.CAT_link %}href='{{ value.CAT_link }}'{% elif value.snippet_cta %}href='{{ value.snippet_cta }}'{% endif %} {% if value.CAT_blank %}target='_blank'{% endif %}>
<button type="button" class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-bluefuf-600 hover:bg-bluefuf-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-bluefuf-900">
{{ value.CAT_title }}
</button>
</a>
{% endif %}
</div>
<div class="text-center py-20 px-4 hidden bg-cover
{% if value.position == '1' %}
sm:inline-block
{% endif %}
"
style='background-image:url("{{ cover.url }}");'>
</div>
</div>
The picture (for example, so in this case 269x540):
and the result:
Thanks a lot in advance for your help

I'd guess that you need to remove the bg-cover class from your <div> element, but without seeing your full CSS setup it's only a guess.
fill-300x600 on the {% image %} tag will generate an image file of maximum resolution 300x600, but since your original image is only 269x540 (and the {% image %} tag never scales an image up) the resulting image file will remain at 269x540.
You're then passing that image as a CSS background-image, which means that unlike an <img> tag where you're explicitly specifying a width and height in the HTML, it's up to the browser (and the rest of the CSS rules) to determine what size to render it at.
With no other CSS rules in place, the browser would default to rendering the image at its native 269x540 resolution, and tiling that across the element it's applied to. However, if your element has background-size: cover applied to it, the image will be resized to cover the whole element, and since the element is wider than 269 pixels, it's zooming the image. Judging from the name, I assume the bg-cover class is adding that background-size: cover rule.

Related

wagtail 'your first site': how do I link to original of gallery image?

In the getting started tutorial for wagtail there is the following code in a template:
{% for item in page.gallery_images.all %}
<div style="float: left; margin: 10px">
{% image item.image fill-320x240 %}
<p>{{ item.caption }}</p>
</div>
{% endfor %}
Please excuse me if I'm missing something obvious but I can't find out how to do this in the docs. How would I link to the original file? eg:
{% image item.image fill-320x240 %}
You'll want to use the {{ img.url }} property in your template.
{% for item in page.gallery_images.all %}
<div style="float: left; margin: 10px">
{% image item.image fill-320x240 as img %}
<p>{{ item.caption }}</p>
{% comment %}
Assign your image `as img` (doesn't need to be `img`, you can
use any alias you'd like
{% endcomment %}
<img href="{{ img.url }}" alt="{{ img.alt }}" />
This is the link to your image
</div>
{% endfor %}
By assigning your image an alias, such as as img (in the code above) you can use {{ img.property_name }} in your template.

add jquery counterup plugin to symfony 2 with assetic

I'm trying to add a counter up effect to my home page in a symfony 2 application with angular . i have added dependencies in my config.yml file like this :
counter:
inputs:
- "bundles/ubidelectricity/js/custom/waypoints.min.js"
- "bundles/ubidelectricity/js/custom/jquery.counterup.min.js"
and i have called counter in my twig like this :
{% block javascripts %}
{% javascripts
'#jquery'
'#bootstrap_4_js'
'#jqueryui'
'#elfinder'
'#fastclick'
'#angular'
'#angular_storage'
'#angular_table'
'#angular_translate'
'#angular_scroll'
'#angular_file_uplaod'
'#angular_dynamic_locale'
'#bootstrap_colorpicker'
'#videogular'
'#oclazyload'
'#breadcrumb'
'#ui_bootstrap'
'#loading_bar'
'#color_picker'
'#locationpicker'
'#multirange_slider'
'#site_front_scripts'
'#continuous_net_services'
'#continuous_net_directives'
'#site_front_controller' %}<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
and i have added html in the front page like this :
<div class="row pt-5 pb-5">
<div class="col-md-3 text-center">
<span class="counter">3300</span> <span class="counters">+</span>
<span class="counter-text">Buyers Organisations</span>
</div>
<div class="col-md-3 text-center">
<span class="counter">585</span>
<span class="counter-text">Buyer Partners</span>
</div>
<div class="col-md-3 text-center">
<span class="counter">41000</span> <span class="counters">+</span>
<span class="counter-text">Tenders / Quotes </span>
<span class="counter-text"> Every Year </span>
</div>
<div class="col-md-3 text-center">
<span class="counter">658</span>
<span class="counter-text">Industry Categories</span>
</div>
</div>
I use :
php app/console assets:install
php app/console assetic:dump
php app/console assetic:watch
but it doesn't work and there are no animations.

Non-clickable menu items in Wagtail

I'd like to have some main menu items which are non-clickable but their children are in drop-down menu and clickable.
I imagine an approach may be as a special type of model which is:
parent to a few pages
inaccessible itself
Or may be more elegant way to do it I don't suspect?
As you mentioned, you are using the example code from here, this is more of a Bootstrap question but here is a potential solution.
Towards the end of the <nav> element you have your container that contains the main menu items.
<div class="container">
<div class="collapse navbar-collapse" id="navbar-collapse-3">
<ul class="nav navbar-nav navbar-left">
{% for menuitem in menuitems %}
<li class="{% if menuitem.active %}active{% endif %}">
{% if menuitem.show_dropdown %}
<a href="{{ menuitem.url }}">{{ menuitem.title }}
<span class="hidden-lg hidden-md hidden-sm visible-xs-inline">
<span class="glyphicon glyphicon-chevron-right"></span>
</span>
</a>
{% top_menu_children parent=menuitem %}
{% else %}
{{ menuitem.title }}
{% endif %}
</li>
{% endfor %}
</ul>
</div>
</div>
To make the menu items not clickable, adjust the href attribute for the menu item. Instead of being {{ menuitem.url }} make it #. This will ensure the menu dropdown still works but there is no URL to take people to the 'parent' page.
<a href="#">{{ menuitem.title }}
<span class="hidden-lg hidden-md hidden-sm visible-xs-inline">
<span class="glyphicon glyphicon-chevron-right"></span>
</span>
</a>
See also: Boostrap 3 Navbar Docs

Drupal 8 responsive layout - not showing responsive behavior in desktop view

I am new to Drupal 8 platform. To start with I am trying to create a responsive layout using Bootstrap, but I don't want to use ready-made bootstrap theme provided by Drupal. Folder structure of my theme looks like this:
themes
custom
lexus
css
style.css
includes
bootstrap
bootstrap-theme.css
bootstrap-theme.css.map
bootstrap.css
templates
page.html.twig
lexus.libraries.yml
lexus.info.yml
Content of page.html.twig
<div id="page">
{% if page.headline %}
<section id="headline">
<div class= "container">
{{ page.headline }}
</div>
</section>
{% endif %}
<header id="header" class="header">
<div class="container">
{{ page.header }}
</div>
</header>
<section id="main">
<div class="container">
<div class="row">
<div id="content" class="col-md-9 col-sm-9 col-xs-12">
{{ page.content }}
</div>
{% if page.sidebar_first %}
<aside id="sidebar" class="sidebar col-md-3 col-sm-3 col-xs-12">
{{ page.sidebar_first}}
</aside>
{% endif %}
</div>
</div>
</section>
{% if page.footer %}
<footer id="footer" class>
<div class="container">
{{ page.footer }}
</div>
</footer>
{% endif %}
</div>
Content of lexus.info.yml
name: Lexus
description: Two column responsive layout
type: theme
core: 8.x
version: 8.2.0
base theme: bartik
libraries:
- lexus/global-styling
Content of lexus.libraries.yml
global-styling:
css:
theme:
includes/bootstrap/css/bootstrap.css: {}
css/style.css: {}
When the site loads in desktop view it does not seem to be using bootstrap column arrangements. The content section is taking up entire browser width and pushing sidebar_first contents below it. Here is a screenshot of my desktop view:
But when I resize my browser to mobile view it looks like the responsiveness works. Here is the screenshot of mobile view.
Please help me understand what I am doing wrong.
This could be due to your device being considered "large" by bootstrap when it is maximised. You don't currently have a "col-lg-X" class. Try changing
<div id="content" class="col-md-9 col-sm-9 col-xs-12">
to
<div id="content" class="col-lg-9 col-md-9 col-sm-9 col-xs-12">

How to assign values to an array using HubSpot's HubL

I'm currently trying to figure out how to allow a content manager to change the order in which elements appear within recent post link lists. Essentially, the concept involves them picking the index in a sorting array that will hold that element's type as a string, which will later be iterated over with output logic determining where each piece gets placed. Unfortunately, one of the drawbacks of using HubL is the lack of debugging or error reporting so I can't see where my syntax is failing. I was wondering if anyone in InternetLand has had any similar experience with this.
Here's the HubL:
<div class="theme-recent-posts">
{% if widget.title_name %}
<div class="theme-recent-posts-title">
<{{ widget.title_tag }}><span>{{ widget.title_name }}</span></{{ widget.title_tag }}>
</div>
{% endif %}
{% set posts = blog_recent_posts(widget.select_blog, widget.max_links) %}
{% for post in posts %}
{% set item_objects = [] %}
{% if widget.show_images == "true" %}
{% set item_objects[widget.sort_images] = "image" %}
{% endif %}
{% if widget.show_titles == "true" %}
{% set item_objects[widget.sort_titles] = "title" %}
{% endif %}
{% if widget.show_dates == "true" %}
{% set item_objects[widget.sort_dates] = "date" %}
{% endif %}
{% if widget.show_authors == "true" %}
{% set item_objects[widget.sort_authors] = "author" %}
{% endif %}
<div class="theme-recent-posts-item">
<a href="{{ post.absolute_url }}">
{% for object in item_objects %}
{% if object == "image" %}
<span class="theme-recent-posts-item-image"><img src="{{ post.featured_image }}" alt="{{ post.name }}" /></span>
{% endif %}
{% if object == "title" %}
<span class="theme-recent-posts-item-title">{{ post.name }}</span>
{% endif %}
{% if object == "date" %}
<span class="theme-recent-posts-item-date">{{ post.created }}</span>
{% endif %}
{% if object == "author" %}
<span class="theme-recent-posts-item-author">{{ post.author_name }}</span>
{% endif %}
{% endfor %}
</a>
</div>
{% endfor %}
</div>
Output currently results in:
<div class="theme-recent-posts">
<div class="theme-recent-posts-title">
<h2><span>Recent Posts</span></h2>
</div>
<div class="theme-recent-posts-item">
</div>
<div class="theme-recent-posts-item">
</div>
<div class="theme-recent-posts-item">
</div>
</div>
Assume the default values wired up in the widget panel:
widget.show_images = true
widget.show_images = true
widget.show_images = true
widget.show_images = true
widget.sort_images = 0
widget.sort_titles = 1
widget.sort_dates = 2
widget.sort_authors = 3
The output should essentially be this:
<div class="theme-recent-posts">
<div class="theme-recent-posts-title">
<h2><span>Recent Posts</span></h2>
</div>
<div class="theme-recent-posts-item">
<a href="//website/path/post-name-3">
<span class="theme-recent-posts-item-image"><img src="path/to/image-3.ext" alt="Post Name 3" /></span>
<span class="theme-recent-posts-item-title">Post Name 3</span>
<span class="theme-recent-posts-item-date">1234567890</span>
<span class="theme-recent-posts-item-author">FirstName LastName</span>
</a>
</div>
<div class="theme-recent-posts-item">
<a href="//website/path/post-name-2">
<span class="theme-recent-posts-item-image"><img src="path/to/image-2.ext" alt="Post Name 2" /></span>
<span class="theme-recent-posts-item-title">Post Name 2</span>
<span class="theme-recent-posts-item-date">1234567890</span>
<span class="theme-recent-posts-item-author">FirstName LastName</span>
</a>
</div>
<div class="theme-recent-posts-item">
<a href="//website/path/post-name-1">
<span class="theme-recent-posts-item-image"><img src="path/to/image-1.ext" alt="Post Name 1" /></span>
<span class="theme-recent-posts-item-title">Post Name 1</span>
<span class="theme-recent-posts-item-date">1234567890</span>
<span class="theme-recent-posts-item-author">FirstName LastName</span>
</a>
</div>
</div>
I'm going to tag Jinja in this post, because HubL is based on Jinja, though it's not a direct translation.
If someone with enough reputation is reading this, I would greatly appreciate the addition of the HubL language tag, as it currently does not exist to select (even though HubSpot was).
Update
Twig is also a close cousin to HubL, and so I looked up how to update elements in an array there, and came up with this answer:
Setting element of array from Twig
{% set item_objects = item_objects|merge({widget.sort_images:"image"}) %}
Implementation did not work as expected. Output remains unchanged.
While this is not an answer to the question I asked, it is an alternate solution, so I provide it as a work around until a real solution is determined.
<div class="theme-recent-posts">
{% if widget.title_name %}
<div class="theme-recent-posts-title">
<{{ widget.title_tag }}><span>{{ widget.title_name }}</span></{{ widget.title_tag }}>
</div>
{% endif %}
{% set object_order = [0, 1, 2, 3] %}
{% set posts = blog_recent_posts(widget.select_blog, widget.max_links) %}
{% for post in posts %}
<div class="theme-recent-posts-item">
<a href="{{ post.absolute_url }}">
{% for order in object_order %}
{% if widget.show_images == "true" and widget.sort_images == order %}
<span class="theme-recent-posts-item-image"><img src="{{ post.featured_image }}" alt="{{ post.name }}" /></span>
{% endif %}
{% if widget.show_titles == "true" and widget.sort_titles == order %}
<span class="theme-recent-posts-item-title">{{ post.name }}</span>
{% endif %}
{% if widget.show_dates == "true" and widget.sort_dates == order %}
<span class="theme-recent-posts-item-date">{{ post.created }}</span>
{% endif %}
{% if widget.show_authors == "true" and widget.sort_authors == order %}
<span class="theme-recent-posts-item-author">{{ post.author_name }}</span>
{% endif %}
{% endfor %}
</a>
</div>
{% endfor %}
</div>
This gives me the flexibility I was looking for and the code is actually lightened quite a bit from the original proposed method. The idea is to use the object_order list as a mask for the for order in object_order loop. This gets the job done, and while I know it's hacky, it has a touch of elegance to it.

Resources