Download the PHP package sgroup/site-module without Composer
On this page you can find all versions of the php package sgroup/site-module. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package site-module
Site Module
A base module for all S. Group sites, featuring a few helpers and scaffolding.
Offline switch
There's a hard-offline setting that's useful for when taking a staging site offline. It's more heavy-handed than Craft's offline behaviour, as we want to prevent anyone from logging into Craft (to save confusion between environments).
Control it in your general.php
config.
Vite & Resources
Adds a @resource
alias for use in templates. This will resolve to either @webroot/../resources
if the dev server is running, or @webroot/dist
if not. The We store our static asset files outside of the webroot.
We also provide a resource()
Twig function that does a similar thing, but resolves to your Vite plugin settings. devServerPublic
if the dev server is running, or serverPublic
if not. In practice this resolves to http://localhost:3000/
and /dist
respectively.
Resources in Twig
Through these, you'll be able to refer to resources like JS, CSS, images and fonts - anything in your /resources
folder in your templates. For example, a common scenario is wanting to include images in your Twig templates. You can use the following options to acheieve this.
If you need to inline an SVG, it's encouraged to use the svg()
Twig function. With this, your only option is to use an alias.
Base module
Yii's modules are pretty slim, and we loose a bunch of boilerplating that Craft plugins get for free. We add this in base/Module
. Every Yii module for a project you create should extend this not Yii's module class.
Twig extensions
We provide a good bunch of Twig extensions for better template development.
svgPlaceholder($width, $height = null)
Given a width and height, this will generate a transparent SVG. This is most commonly used for the src
attribute of <img>
tags when lazyloading. This creates the correct dimensions for the image, while the real image is being lazyloaded. Doing this prevent a noticable "jump" when going from an image on zero dimensions to the proper one.
getFormattedPhone($value)
An opinionated, AU-based phone formatter. Throw it any phone number and it'll internationalize it, deal with spaces and area codes, ready for use in <a href="tel:"
getVideo($asset, $settings = [])
Given an asset, this will render an <iframe>
or <video>
. This handles both Embedded Asset plugin videos, or real uploaded videos. For any YouTube-based embedded asset, it'll render an <iframe>
and embed the video URL.
You can also pass in attributes to be used either in the URL (as URL-encoded params) or in <video>
attributes. You can include any attribute, but some worth mentioning:
Option | Description |
---|---|
muted |
Whether the video should be muted. |
autoplay |
Whether the video should autoplay. |
controls |
Whether the video controls should be shown. |
getImg($image, $transform = null, $lazyload = false, $attributes = [], $sizes = 'default')
This will return an <img>
tag, pre-configured with a bunch of options.
Option | Description |
---|---|
image |
The asset. |
transform |
Either an array (for dynamic transform) or string for the transform. |
lazyload |
Whether the the image should be lazyloaded. |
attributes |
A collection of attributes, added to the <img> element. |
sizes |
An array of valid sizes, used for srcset . |
By default, we use srcset
to provide ['1x', '1.5x', '2x', '3x']
sizes.
Focal point
If a focal point is defined on the image, it'll be output via inline style rules.
getImgAttr()
This has the same options as getImg()
except the $attributes
. This will return an object of attributes for you to apply on your own. Ideally, you'd use the {{ attr() }}
function.
You'll notice on the instances we're using lazyloading
the need to manually include the lazyload
class because we're rendering the classes on our own. Alternatively, you could do:
This would combine the img-cover
class in the template and the lazyload
class from the function.
getBg()
This behaves in almost the exact same manner as getImg()
but returns a <div>
element.
Focal point
If a focal point is defined on the image, it'll be output via inline style rules.
getBgAttr()
This behaves in almost the exact same manner as getImgAttr()
, just with different attributes.